
-----------------------------------
Carey
Thu Apr 17, 2008 10:09 am

Traversing Directories
-----------------------------------
Im making a tagging program (like windows search on 'roids) and i need help on how to add multiple files.

Turing example:

var temp : string
procedure addDir (path : string)
    var streamNumber := Dir.Open (path)
    loop
        temp := Dir.Get (streamNumber)
        exit when temp = ""
        if File.Exists (path + "/" + temp) then
            addFile (path + "/" + temp) %add the file
        elsif temp not= "." and temp not= ".." then
            addDir (path + "/" + temp)
        end if
    end loop
    Dir.Close (streamNumber)
    Dir.Delete (path)
end addDir

any help would be muchly appreciated

-----------------------------------
Carey
Fri Apr 18, 2008 11:44 am

RE:Traversing Directories
-----------------------------------
anyone?

-----------------------------------
Tony
Fri Apr 18, 2008 12:03 pm

RE:Traversing Directories
-----------------------------------
eh.. call addFile multiple times? It's not clear what your question is.

-----------------------------------
Carey
Fri Apr 18, 2008 12:15 pm

RE:Traversing Directories
-----------------------------------
I want to go through a directory recursively, adding every file in it and going into every directory. my problem is that i don't know how to get the names and paths of every file and sub-directory inside the initial directory passed to the method. tell me if i'm not making sense.

-----------------------------------
Tony
Fri Apr 18, 2008 12:36 pm

RE:Traversing Directories
-----------------------------------
Dir.Get returns the "next" item in the directory. If it's a file (File.Exists), you add it to the list. Otherwise you assume it's a directory, and recursively examine that. The sample code already does just this

procedure addDir (path : string) 
   ...
   addDir (path + "/" + temp) 
   ...
end addDir


-----------------------------------
Carey
Fri Apr 18, 2008 12:40 pm

RE:Traversing Directories
-----------------------------------
I know that. I need help on porting this method into Java. I don't know how to get the paths and such of all the items in a directory in Java. i've searched the online help file and tutorials but i haven't found anything. I just gave the Turing example to clarify what i need to accomplish.

-----------------------------------
Tony
Fri Apr 18, 2008 1:37 pm

RE:Traversing Directories
-----------------------------------
Ohh... I haven't noticed that this was in Java. Sorry. What do Java Docs say about the File class?

-----------------------------------
Carey
Mon Apr 21, 2008 10:48 am

RE:Traversing Directories
-----------------------------------
hmmmmm. I think i have it
public void addDir(String path, boolean auto){
        String);
            if (f.isDirectory())
                addDir(f.getAbsolutePath(), auto);
            else if (f.isFile())
                addFile(f.getAbsolutePath(), auto);
        }
    }


hmmmmm. doesn't seem to work. any ideas?

crap. 
public void addDir(String path, boolean auto){
        File

my question now is:

What is Java's definition of a . Is a hidden file normal?

A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria.

Do these system-dependent criteria specify that it has to be visible(not hidden)?

