![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0
![]() |
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 ![]() |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
It's easy enough:
import glob
files = glob.glob("*.txt") + glob.glob("*.ini")
files.sort()
for file in files:
# la de da |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|