How can I go to each subfolder in a given directory and take a pdf file from there like wise collect all pdf from all subfolders and move to a common folder?.
I've tried below code which is failing.
import java.io.File;
import java.io.IOException;`enter code here`
import java.nio.file.Files;
import java.util.ArrayList;
public class PDFMover{
/**
* @param args
* @return
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File mainfolder = new File("C:\\Users\\myuser\\Desktop\\X\\Report");
File[] fulllist = mainfolder.listFiles();
ArrayList<String> listofpath = new ArrayList<String>(fulllist.length);
for (File x : fulllist)
{
if (x.isDirectory())
{
System.out.println("Directory:" +x.getName());
}
else
{
System.out.println("Notfound");
}
}
String source = "C:\\Users\\myuser\\Desktop\\X\\Report";
String destination ="C:\\Users\\myuser\\Desktop\\Destination";
File f1 = new File(source);
File f2 = new File(destination);
for (File x : fulllist)
{
if(mainfolder.isDirectory())
{
Files.copy(f1.toPath(), f2.toPath());
}
}
}
}