wrapped around the axle on regexpressions and file searching

msrisney at my-dejanews.com msrisney at my-dejanews.com
Sat Apr 24 00:30:56 EDT 1999


Hey Pythoniers!

I'm attemtping to locate log files on my drive(s), and do some comparison.
here's a simplified snippet where I'm getting bottlenecked.

>>>import os,re
>>>regexp = re.compile('.log')
>>>def find_log_files(arg, directory, names):
 ...for name in os.listdir(directory):
        if regexp.search(name):
           print directory + "\\" + name
>>>os.path.walk('D:\\',find_log_files,None)


here are my questions: 1. this prints  out not only files with the file
extensions ".log" but also any file name that has "log" in it's name. how
would I rewrite to avoid??

2. is there a better, faster way of doing this??, my end goal is to open the
files and compare time sequences to one another.

3. Is ther any way to determine the number of drives on a system, obviuosly I
am hardcoding the top level drive letter "D:\", is there any way to search the
entire system much like win32's find file search??

TIA

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




More information about the Python-list mailing list