Created
January 10, 2009 13:38
-
-
Save commana/45456 to your computer and use it in GitHub Desktop.
UTF-8 File Conversion for Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code by Anton Afanasjew | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
public class FileListExample { | |
public static final String CMD = "run.cmd"; | |
public static final String ROOT = "files"; | |
static String line = ""; | |
static InputStream stderr = null; | |
static InputStream stdout = null; | |
static int COUNT = 0; | |
public static void main(String[] args) throws Exception { | |
treeWalk(new File(ROOT)); | |
System.out.println(COUNT); | |
} | |
static void treeWalk(File src) throws Exception { | |
if (src.isDirectory()) { | |
File[] children = src.listFiles(); | |
for (File child : children) { | |
treeWalk(child); | |
} | |
} else { | |
if (isRelevantFile(src)) { | |
COUNT++; | |
process(src); | |
} | |
} | |
} | |
static void process(File f) throws Exception { | |
Process process = Runtime.getRuntime().exec(CMD + " " + "\"" + f.getAbsolutePath() + "\""); | |
stderr = process.getErrorStream(); | |
stdout = process.getInputStream(); | |
BufferedReader brCleanUp = new BufferedReader(new InputStreamReader(stdout)); | |
while ((line = brCleanUp.readLine()) != null) { | |
System.out.println(line); | |
} | |
brCleanUp.close(); | |
brCleanUp = new BufferedReader(new InputStreamReader(stderr)); | |
while ((line = brCleanUp.readLine()) != null) { | |
System.out.println(line); | |
} | |
brCleanUp.close(); | |
process.waitFor(); | |
} | |
static boolean isRelevantFile(File f) { | |
return | |
f.getName().endsWith(".php") || | |
f.getName().endsWith(".html")|| | |
f.getName().endsWith(".txt") || | |
f.getName().endsWith(".sql") || | |
f.getName().endsWith(".mkf") || | |
f.getName().endsWith(".xml") || | |
f.getName().endsWith(".css") || | |
f.getName().endsWith(".js"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iconv -f cp1252 -t utf-8 %1 > %1.oldfiletodelete | |
copy %1.oldfiletodelete %1 | |
del %1.oldfiletodelete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment