| 1 |
package fileIO; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
|
| 5 |
|
| 6 |
public class CopyFiles { |
| 7 |
|
| 8 |
|
| 9 |
public static void main(String[] args){ |
| 10 |
for(String s : args){ |
| 11 |
renameFiles(s); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
public static void renameFiles(String path){ |
| 17 |
File f=new File(path); |
| 18 |
renameFiles(f); |
| 19 |
} |
| 20 |
|
| 21 |
public static void renameFiles(File path){ |
| 22 |
|
| 23 |
if(path.isDirectory()){ |
| 24 |
File[] array=path.listFiles(); |
| 25 |
for(File f : array){renameFiles(f);} |
| 26 |
}else{ |
| 27 |
rename(path); |
| 28 |
} |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
public static void rename(File in){ |
| 33 |
assert(in.exists()); |
| 34 |
assert(in.isFile()); |
| 35 |
String abs=in.getAbsolutePath(); |
| 36 |
|
| 37 |
|
| 38 |
int dot=abs.lastIndexOf('.'); |
| 39 |
int slash=abs.lastIndexOf('/'); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
String fname=abs.substring(slash+1); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
if(fname.startsWith("chr") && fname.endsWith(".txt")){ |
| 53 |
|
| 54 |
String out=abs.replace(".txt", ".flow"); |
| 55 |
assert(!out.equals(abs)) : out+", "+abs; |
| 56 |
|
| 57 |
System.out.println("Renaming "+abs+" to "+out); |
| 58 |
ReadWrite.copyFile(abs, out); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
} |