Game Development Community

FindFirstFolder() ?

by Orion Elenzil · in Torque Game Engine · 11/27/2007 (11:24 am) · 4 replies

TorqueScript has findFirstFile(),
but do we have FindFirstFolder() or equivelant ?

(i don't think so)

any tips on implementing something like that ?

#1
11/27/2007 (1:55 pm)
As I understand it, early on in startup, the modPaths are traversed to collect and create a bunch of file references in the ResManager.

By the time you are doing something like a findFirstFile(), ResManager contains a list of all the files found in the earlier traversal, and they are in reverse traversal order. Calls to findFirstFile() and its kin, are not actually traversing the file system, they are linearly traversing the ResManager's list.

Given this, the easiest way to do a findFirstFolder() would probably be to create a modified find function that kept track of the last folder found. Basically, while it was traversing, it would treat the first file found in a particular folder and then pretend that that file was actually the folder, and skip over any other files in the same folder until it found the first file in a different folder, etc.

Make sense?
#2
11/27/2007 (1:58 pm)
Hey Jeff -

roger that,
that was pretty much how i was going to go about it.

one problem there is that it won't see empty folders,
but that's okay for my purposes.

also it might be a little tricky to make sure it Does see folders which contain only folders,
but that should be do-able.

thanks!
#3
11/27/2007 (2:22 pm)
Good point about the empty folders, I didn't think of that, and you would never find those. For that, I think you would end up customizing both the ResManager and the platform code that does the filesystem traversal.
#4
11/27/2007 (2:53 pm)
Fwiw, i've decided to chicken out of this and instead infer the folder structure from the files found in it.
thanks again for the advice!