Count Files in a Directory

hokieghal99 hokiegal99 at hotmail.com
Tue Dec 23 08:52:12 EST 2003


Robin Munn wrote:
> I wonder if symlinks or hard links might account for the difference?
> 
> Here's an idea: modify your script to print (on stdout) the name of each
> filesystem object found. Do the same with the OS's functions. Then
> compare the two. I.e., on a Unix system, something like:
> 
>     (Modify Python script to print full paths to stdout)
>     python myscript.py /some/path > python_file_list.txt
>     find /some/path -print > find_file_list.txt
>     sort python_file_list.txt > python_file_list_sorted.txt
>     sort find_file_list.txt > find_file_list_sorted.txt
>     diff -u find_file_list_sorted.txt python_file_list_sorted.txt
>     rm find_file_list*txt python_file_list*txt
> 
> That should tell you precisely which file is being found by the Python
> script but isn't being found when you get the OS to do the work.
> 

This is very good. I will test it out today. Not sure exactly where the 
difference is coming from. I noticed last night that when the script is 
ran as root that Python counts many more files than the OS does... maybe 
it is a permission issue too. Thnaks again!!!





More information about the Python-list mailing list