Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 7th, 2005, 6:50 PM   #1
Joe silly
Newbie
 
Join Date: Mar 2005
Posts: 1
Rep Power: 0 Joe silly is on a distinguished road
Searching for files

Hi

I have this code:
Import glob
For files in glob.glob('*.txt')
To search current dir for all txt files. But i also want to search for .ini files so i was thinking:
For files in glob.glob('*.txt, *.ini')
I know that dont work but you get the idea? So any ideas how i can search for both .txt .ini files in current dir?


Thanx
Joe silly is offline   Reply With Quote
Old Mar 7th, 2005, 7:15 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
It's easy enough:
import glob

files = glob.glob("*.txt") + glob.glob("*.ini")
files.sort()

for file in files:
    # la de da
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 8th, 2005, 2:49 AM   #3
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

A bit more complex, but allows you to add the path.
import os

fileList = []
path = 'C:/Windows/'
for file in os.listdir(path):
  if (file.endswith('.txt') | file.endswith('.ini')):
    fileList.append(file)

print "\nAll the .ini and .txt files in %s:" % path
print "\n".join(fileList)
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:48 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC