dkim18
asked on
how to write up a batch file?
Hi,
I have a java app which takes one file name and check something and returns a message (pass or fail)
1) I need to write up a batch file to run on a folder contains files and subfolders.
2) also I need to copy the failed files to another folder with the same folder structure as the original
Input folder
A
A/file1
A/1/file2
A/B/file3
A/E/file4
output folder
A
A/
A/1/file2 <==if file fails the test
A/B/
A/E/
Can you help me how I need to kickstart please?
Is there an example I can take a look?
I have a java app which takes one file name and check something and returns a message (pass or fail)
1) I need to write up a batch file to run on a folder contains files and subfolders.
2) also I need to copy the failed files to another folder with the same folder structure as the original
Input folder
A
A/file1
A/1/file2
A/B/file3
A/E/file4
output folder
A
A/
A/1/file2 <==if file fails the test
A/B/
A/E/
Can you help me how I need to kickstart please?
Is there an example I can take a look?
Look at this code - which traverses the filess recursivelt through subdirectories:
http://www.java-forums.org/new-java/4123-how-do-you-recursively-traverse-through-file-folders.html
http://www.java-forums.org/new-java/4123-how-do-you-recursively-traverse-through-file-folders.html
import java.io.File;
import java.util.*;
public class GatheringFiles {
public static void main(String[] args) {
File folder = new File(".");
List<File> list = new ArrayList<File>();
getFiles(folder, list);
System.out.println("list.size = " + list.size());
}
private static void getFiles(File folder, List<File> list) {
folder.setReadOnly();
File[] files = folder.listFiles();
for(int j = 0; j < files.length; j++) {
list.add(files[j]);
if(files[j].isDirectory())
getFiles(files[j], list);
}
}
}
Howevere you probably do not ned to create list of files - you ca use thre aasaem ideology - and then
check each file and then use mkdirs() method to create the path for the file which needs to be copied and coopy the file
to the new location
check each file and then use mkdirs() method to create the path for the file which needs to be copied and coopy the file
to the new location
you ca use the static method from here to do the actual copying of the files:
http://www.roseindia.net/java/beginners/CopyFile.shtml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I want to write up a java app or a batch file to process the folder.
My java application handles one file
java CheckPdforNot filename
Then it returns a string "Not PDF" or "PDF"
If it is not pdf, I want to copy that from the input folder and put it in the output folder and need to keep same folder structure.