FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

java help

 


clydejaw
At the moment I'm trying to figure out how to do a search through a folder and list all the files by using System.out.

I am currently using a forloop to trace all the files, but it could only trace one folder. My objective is to go through every folders in one particular folder, it thats not confusing.

E.G.

search directory folder: folder1...

file1
file2
file3...
folder2 <---- how do i make it so it includes folder 2?

Is there any easier way than using a forloop?

cheers.
MrBlueSky
Make a function that loops trough the directory and calls itself recursively when it encounters a folder:

Pseudocode:

Code:


function processFiles(Folder folder) {

  while ((item = nextitem in Folder) != null) {

    if (item is file) {
       // do something with file
    }
    if (item is folder) {
       processFiles(item)
    }

}



Or post the code you have so far so I can be more concrete. But this should help you on your way.
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.