views:

70

answers:

3

How do I get the list of all the files in a directory? It should give me only files, and it should search through all the subdirectories, and the directories inside them etc. Basically the entire folder structure.

I have thousands of files and directories. I wrote a recursive function, but it is super slow. Is there any command or trick that can do this quickly? It has to run in windows and mac though.

+2  A: 

Recursing a file system is slow. Especially if you're trying to make it cross platform.

John Weldon
+1  A: 

You didn't clarify if you wanted to do something with the list, just dump it to the console, or anything else, and most importantly, what language you would like to use.

Most standard libraries have means for traversing directory trees. For example, Python has a convenient os.walk (google for that and you'll find many examples). You can apply a variety of filters to get just the stuff you care for. A similar facility is available in Java and in perl. All three languages are portable.

That being said, a lot of the actual processing takes place at the OS level. Some OSs are slower than others in facilitating file system traversal. You are also most likely hitting the disk which adds slowness on a different order of magnitude.

Uri
+1  A: 

ok, I found this one, this is much faster than my recursive function...

http://www.rooftopsolutions.nl/article/177