I had some directory, with large number of files. Every time I tried to access the list of files within it, I was not able to do that or there was significant delay. I was trying to use ls
command within command-line on Linux and web interface from my hosting provider did not help also.
The problem is, that when I just do ls
, it takes significant amount of time to even start displaying something. Thus, ls | wc -l
would not help also.
After some research I came up with this code (in this example it counts number of new emails on some server):
print sum([len(files) for (root, dirs, files) in walk('/home/myname/Maildir/new')])
The above code is written in Python. I used Python's command-line tool and it worked pretty fast (returned result instantly).
I am interested in the answer to the following question: is it possible to count files in a directory (without subdirectories) faster? What is the fastest way to do that?
所有评论(0)