Good morning,
The problem I have is that I need to search for one or more files within one or more folders.
Code1 :
String path = "C:\\Users\\ProKode\\Desktop\\PruebaBuscar";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
files = listOfFiles[i].getName();
System.out.println(files);
}
}
Output Code1:
run: Hello.txt BUILD SUCCESSFUL (total time: 0 seconds)
_
Folder Image:
Inside the folder there are subfolders and inside them there are files
That is to say that it is not looking for the files that are inside the other folders.
What I need is for me to find everything that is inside the folder
End Output:
The file Hello.txt was found inside the TestSearch folder.
The file Text1.1.txt was found inside the folder Capeta1.
The file Text1.2.txt was found inside the folder Folder1.
The file Text1.3.txt was found inside the folder Folder1.
The file Text2.1.txt was found inside the Folder2 folder.
The file Text2.2.txt was found inside the folder Folder2.
The file Text2.3.txt was found inside the folder Folder2.
The file Text3.1.txt was found inside the folder Folder3.
The file Text3.2.txt was found inside the folder Folder3.
The file Text3.3.txt was found inside the folder Folder3.
Thank you so much.
Try this one, called recursive form:
If you are using Java 7, you can use Java File IO (NIO.2). Namely: