473,378 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

glob() that traverses a folder tree

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.

May 11 '06 #1
3 2164
# 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

May 11 '06 #2
se**********@yahoo.com 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
May 11 '06 #3
awesome. thanks.

May 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Georgy Pruss | last post by:
On Windows XP glob.glob doesn't work properly for files without extensions. E.g. C:\Temp contains 4 files: 2 with extensions, 2 without. C:\Temp>dir /b * aaaaa.aaa bbbbb.bbb ccccc ddddd ...
4
by: Python Dunce | last post by:
I've run into an issue with glob and matching filenames with brackets '' in them. The problem comes when I'm using part of such a filename as the path I'm passing to glob. Here's a trimmed down...
3
by: scott | last post by:
I'm creating a tree menu that uses FSO to read folders, subfolders and files. I'd like for each folder to have capabilty of being either Level 1,2,3,4 or 5 security. The 5 Levels are my security...
0
by: John H. | last post by:
In effort to understand (Outlook) MAPI folder tree structure wrote simple linear code below to navigate tree. Successive "...Folders.GetNext()"'s return same folder at all levels of tree. What...
6
by: Hitesh | last post by:
import string import os f = open ("c:\\servername.txt", 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog #print lineLog for l in lineLog:
5
by: PythonNewbie | last post by:
Hello, so I needed to write a quick code that lets me merge whole bunch of text files in a given folder into one text file. So, I wrote this up after reading about glob import glob...
2
by: J | last post by:
Greetings Group- I'm trying to put together a pattern matching script that scans a directory tree for tif images contained in similar folder names, but running into a NewB problem already. Is it...
3
by: billiejoex | last post by:
os.listdir(path) return a list of file names independently if the path- argument used is absolute or relative: '/home/user' glob.glob, instead, return file names only if given path is...
2
by: Franz Marksteiner | last post by:
Hi folks, is there a way to negate a glob() pattern? What I want is to get a tree structure, e.g. all .php files *and* all directories. How would I start here? -- Freundliche Grüße, Franz...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.