GetDirectories usage

Caravelle

Active Member
Licensed User
Longtime User
Sorry to be a pain, but after a long time away I need to write a quick program and I can't remember how some things work any more.

Using the FilesEx library, what precisely do I do to get a list of subdirectories in a given directory into a ListBox or ArrayList? The help says:

GetDirectories(Path As String, Pattern as String) : Returns a string array containing the names of all directories within the directory specified by Path and matching the search pattern.

A simple example would really help here. I have no need of any "pattern" of directory names, I just want them all listed. The compiler doesn't seem to like * or "*" but it does accept the line if I leave this part blank, as:
B4X:
GetDirectories(SearchPath, )
(SearchPath is a string variable previously set). If I did want a pattern, what would it look like?

I can't get my head around the idea of "returns a string array" either. Does this mean that you have to dimension an array, and somehow transfer the directory names into it, and then parse one by one through the array items to transfer them into the ListBox? I have tried various approaches and all I end up with is a ListBox containing the single word "array" !

The worst thing is, I managed to make this work about a year ago, but the code is mysteriously missing from my PC... :sign0161:

Thanks in advance for any helpful clues

Caravelle
 

Caravelle

Active Member
Licensed User
Longtime User
Thank you very much, Erel. That's more or less what I had. But even with your version all I got was an empty listbox.

However, after trying several combinations I finally managed to make it work with this construction:

B4X:
Dirs() = FilesEx1.GetDirectories(SearchDir, "*")

Now to move on to the rest of the program, which is going to rename a vast number of photo filenames rather faster than I can do it manually.

Thanks again.

Caravelle
 
Top