| 1 |
package fileIO; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
|
| 5 |
import shared.Timer; |
| 6 |
|
| 7 |
|
| 8 |
public class CopyFiles2 { |
| 9 |
|
| 10 |
|
| 11 |
public static void main(String[] args){ |
| 12 |
|
| 13 |
Timer t=new Timer(); |
| 14 |
|
| 15 |
if(args.length>0){ |
| 16 |
assert(args.length==2); |
| 17 |
inRoots=new String[] {args[0]}; |
| 18 |
outRoot=args[1]; |
| 19 |
} |
| 20 |
|
| 21 |
for(String inRoot : inRoots){ |
| 22 |
copyFiles(inRoot, outRoot); |
| 23 |
} |
| 24 |
|
| 25 |
t.stop(); |
| 26 |
System.out.println("Time:\t"+t); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
public static void copyFiles(String in, String out){ |
| 31 |
File fin=new File(in); |
| 32 |
File fout=new File(out); |
| 33 |
copyFiles(fin, fout); |
| 34 |
} |
| 35 |
|
| 36 |
public static void copyFiles(File in, File out){ |
| 37 |
|
| 38 |
String abs=in.getAbsolutePath(); |
| 39 |
for(String s : badNames){ |
| 40 |
if(abs.matches(s)){ |
| 41 |
return; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
{ |
| 46 |
String temp=out.getAbsolutePath(); |
| 47 |
if(temp.endsWith("\\ASM")){ |
| 48 |
temp=temp.replace("\\ASM", ""); |
| 49 |
}else if(temp.contains("\\ASM\\")){ |
| 50 |
temp=temp.replace("\\ASM\\", ""); |
| 51 |
} |
| 52 |
out=new File(temp); |
| 53 |
} |
| 54 |
|
| 55 |
if(in.isDirectory()){ |
| 56 |
|
| 57 |
if(!out.exists()){ |
| 58 |
out.mkdir(); |
| 59 |
} |
| 60 |
|
| 61 |
File[] array=in.listFiles(); |
| 62 |
for(File f : array){ |
| 63 |
|
| 64 |
|
| 65 |
String outname=out.getAbsolutePath()+"\\"+f.getName(); |
| 66 |
|
| 67 |
File f2=new File(outname); |
| 68 |
copyFiles(f, f2); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
else{ |
| 73 |
copyFile(in, out); |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
public static void copyFile(File in, File out){ |
| 79 |
assert(in.exists()); |
| 80 |
assert(in.isFile()); |
| 81 |
|
| 82 |
if(out.exists()){ |
| 83 |
System.out.println("Skipping existing file "+out.getAbsolutePath()); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
String abs=in.getAbsolutePath(); |
| 88 |
String fname=in.getName(); |
| 89 |
|
| 90 |
boolean valid=false; |
| 91 |
|
| 92 |
for(String s : badNames){ |
| 93 |
if(fname.matches(s)){ |
| 94 |
valid=false; |
| 95 |
return; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
for(String s : dirNames){ |
| 100 |
if(abs.contains(s)){ |
| 101 |
valid=true; |
| 102 |
break; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
for(String s : fileNames){ |
| 107 |
if(valid){break;} |
| 108 |
if(fname.matches(s)){ |
| 109 |
valid=true; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
if(!valid){return;} |
| 114 |
|
| 115 |
if(abs.endsWith(".tsv")){ |
| 116 |
out=new File(out.getAbsolutePath()+".zip"); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
System.out.println("Copying file to "+out.getAbsolutePath()); |
| 124 |
ReadWrite.copyFile(in.getAbsolutePath(), out.getAbsolutePath()); |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
public static String[] inRoots={"F:\\UTSW_second_set\\"}; |
| 130 |
public static String outRoot="C:\\Data\\OCT_8\\"; |
| 131 |
|
| 132 |
public static final String[] dirNames={"\\CNV\\", "\\SV\\"}; |
| 133 |
|
| 134 |
public static final String[] fileNamesAbsolute={ |
| 135 |
".*\\\\gene-GS.+-ASM.*\\.tsv.*", |
| 136 |
".*\\\\geneVarSummary-GS.+-ASM.*\\.tsv.*", |
| 137 |
".*\\\\summary-GS.+-ASM.*\\.tsv.*", |
| 138 |
".*\\\\var-GS.+-ASM.*\\.tsv.*", |
| 139 |
".*\\\\manifest\\.all", |
| 140 |
".*\\\\README\\..*", |
| 141 |
".*\\\\version", |
| 142 |
}; |
| 143 |
|
| 144 |
public static final String[] fileNames={ |
| 145 |
"gene-GS.+-ASM.*\\.tsv.*", |
| 146 |
"geneVarSummary-GS.+-ASM.*\\.tsv.*", |
| 147 |
"summary-GS.+-ASM.*\\.tsv.*", |
| 148 |
"var-GS.+-ASM.*\\.tsv.*", |
| 149 |
"manifest\\.all", |
| 150 |
"README\\..*", |
| 151 |
"version", |
| 152 |
}; |
| 153 |
|
| 154 |
public static final String[] badNames={ |
| 155 |
".*AppleDouble.*", |
| 156 |
".*DS_Store.*", |
| 157 |
".*EVIDENCE.*" |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
} |