Take the 2-minute tour ×

I need the Python code to recursively search through a given path and return the number of files, folders and symbolic links within the location passed in? It should just do the search of the directory once and then increment the value of num of files, num of dirs, num of symbolic links as it is executed. It shouldn't be 3 separate searches of the directory tree for each value. Help really appreciated.

share|improve this question
Hi! In order to get useful answers, you'll need to ask a specific question about a programming problem and show some code you've tried. See the FAQ for the site usage guide. As for your problem, start by looking at os.path module. When you have some code and run into a specific problem, the community will be happy to help you. –  Lev Levitsky Apr 23 '12 at 12:52
add comment

1 Answer

Start with the example from the python library documentation for os.walk it is close to what you need. Test the directorynames and filenames with os.path.islink to seperate the dirs/files from the links. Keep three counters in the local environment, one for each of the things you want to count.

share|improve this answer
add comment

Your Answer


