Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > glob() that traverses a folder tree

Reply
Thread Tools

glob() that traverses a folder tree

 
 
seannakasone@yahoo.com
Guest
Posts: n/a
 
      05-11-2006
i'm looking for something like glob.glob() that traverses
sub-directories. is there anything like that? i guess i'm looking for
something to replace the unix find command.

 
Reply With Quote
 
 
 
 
seannakasone@yahoo.com
Guest
Posts: n/a
 
      05-11-2006
# i'm guessing os.walk() is the best way to traverse folder trees.

import os, glob

for dir, subdir, files in os.walk('.\InteropSolution'):
for file in files:
if glob.fnmatch.fnmatch(file,"*.dll") or
glob.fnmatch.fnmatch(file,"*.exe"):
print dir+file

 
Reply With Quote
 
 
 
 
Kent Johnson
Guest
Posts: n/a
 
      05-11-2006
wrote:
> # i'm guessing os.walk() is the best way to traverse folder trees.
>
> import os, glob
>
> for dir, subdir, files in os.walk('.\InteropSolution'):
> for file in files:
> if glob.fnmatch.fnmatch(file,"*.dll") or
> glob.fnmatch.fnmatch(file,"*.exe"):
> print dir+file


Or use Jason Orendorff's path module. For a single glob it is very easy:

import path
for f in path.path('.\InteropSolution').walkfiles('*.dll'):
print f

For multiple globs you have to work a little harder:
for f in path.path('.\InteropSolution').walkfiles():
if f.fnmatch('*.dll') or f.fnmatch('*.exe'):
print f

or maybe
for f in path.path('.\InteropSolution').walkfiles():
if f.ext in ['.dll', '.exe']:
print f

http://www.jorendorff.com/articles/p...ath/index.html

Kent
 
Reply With Quote
 
seannakasone@yahoo.com
Guest
Posts: n/a
 
      05-12-2006
awesome. thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
B+ Tree versus Ternary Search Tree Ramkumar Menon Java 2 08-16-2005 08:13 PM
B+ Tree versus Ternary Search Tree Ramkumar Menon Java 0 08-16-2005 09:01 AM
B tree, B+ tree and B* tree Stub C Programming 3 11-12-2003 01:51 PM
Spanning Tree And Per Vlan Spanning Tree Amy L. Cisco 0 07-24-2003 10:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57