I suspected as much! I solved it by creating a variable 'z' of type File in the first for loop. Then in the second for loop I assigned the record at hist[j] to z so I could use it later! To test that the size checking was working I modified one of the files and got this output:
*Duplicate File: - C:\DIFFCHECK\DIR1\T0000117.075Q - 318 - C:\DIFFCHECK\DIR2\T0000117.075Q - 532
*Duplicate File: - C:\DIFFCHECK\DIR1\T0000122.305Q - 1876 - C:\DIFFCHECK\DIR2\T0000122.305Q - 1876
*Duplicate File: - C:\DIFFCHECK\DIR1\T0000127.305Q - 3106 - C:\DIFFCHECK\DIR2\T0000127.305Q - 3106
Works great! Here's my code, hope the formatting comes out right when I paste it. Those unused imports are because this is my 'working' version for my own simplicity/sanity. The final outputs a log file.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
public class diffcheck2
{
public static void main(String[] args) throws IOException
{
//populate the arrays
File f = new File("C:/DIFFCHECK/DIR1/");
File[] rec = f.listFiles();
File g = new File("C:/DIFFCHECK/DIR2/");
File[] hist = g.listFiles();
for(int i=0;i<rec.length;i++){
boolean found = false;
File z = null;
for(int j=0;j<hist.length;j++){
if((rec[i].getName().equals(hist[j].getName()))){
found = true;
z = hist[j];
break;
}
}
if (found) {
System.out.println("*Duplicate File: "+
/*rec[i].getName() +*/ " - " +rec[i] + " - " + rec[i].length()+ " - " + z + " - " + z.length()
);
}
}
}
}

New Topic/Question
Reply




MultiQuote




|