[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: search entire drive say c:

Tim Chase

2/12/2010 1:01:00 PM

> can any of u help to search a file say "abc.txt" in entire c drive (windows)
> and print the path/s stating such a files presence.

Well, you can just do it from DOS:

c:\> dir /s/b/a abc.txt

Just use os.walk() and check the list of files returned at each
directory-level iteration.

ROOT = "c:\\"
fname = "abc.txt".lower()
for p, d, f in os.walk(ROOT):
for fn in f:
if fn.lower() == fname:
print os.path.join(p, f)
# break

You might also investigate using os.path.normcase() instead of
..lower()

-tkc


1 Answer

McColgst

2/12/2010 7:37:00 PM

0


>    ROOT = "c:\\"
>    fname = "abc.txt".lower()
>    for p, d, f in os.walk(ROOT):
>      for fn in f:
>        if fn.lower() == fname:
>          print os.path.join(p, f)
>          # break

I think you mean

print os.path.join(p,fn)

-sean