shanenin Posted September 26, 2005 Report Share Posted September 26, 2005 I have been messing around with searching for files on a computer(using python). I wanted to search for all files on my c drivce that end with '.avi'. this little script found them in 16 seconds. A similar search with windows search feature took 50 seconds.import osfor i in os.walk('c:/'): for j in i[2]: if j.endswith('.avi'): base = os.path.abspath(i[0]) print "%s\%s"%(base, j) raw_input('enter retrun to exit') Quote Link to post Share on other sites
jcl Posted September 26, 2005 Report Share Posted September 26, 2005 (edited) Search is a bit odd. It seems to do a depth-first search under Documents and Settings and breadth-first, with no obvious ordering, everywhere else. But not quite. It almost makes sense. Could just be because of what I'm searching for, I guess.It doesn't surprise me that your script is faster. It would surprise me a bit if it was consistently faster. Edited September 26, 2005 by jcl Quote Link to post Share on other sites
shanenin Posted September 26, 2005 Author Report Share Posted September 26, 2005 (edited) I tried to do something different, it still seems quite faster. I searched for all files containing the string 'the' in the titile, and are more then 1mb in size. To keep it even I had windows search all hidden and system folders also. this python script did it in 18 seconds, the windows search feature did it in 48 seconds. import osdef pysearch(word): for i in os.walk('c:/'): for j in i[2]: if j.rfind(word) != -1: base = os.path.abspath(i[0]) full_path = "%s\%s"%(base, j) if os.path.getsize(full_path) >= 1024000: print full_path pysearch('the')raw_input('enter retrun to exit')edit added later//the windows search may be doing some other useful(or bloatful) stull that the python search is not doing. Edited September 26, 2005 by shanenin Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.