|
Quellcode
|
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
|
#!/usr/bin/env python
"""filefinder.py -- Version 05-Nov-2004
Find and list files according to a file mask in subdirectories.
Copyright (c) 2004 Jochen Kupperschmidt <webmaster@homework.nwsnet.de>
Released under the terms of the GNU General Public License
_ _
| |_ ___ _____ ___ _ _ _ ___ ___| |_
| | . | | ._| | | | . | _| . /
|_|_|___|_|_|_|___|_____|___|_| |_|_\
[url]http://homework.nwsnet.de/[/url]
"""
import os
def findfiles(path, extension, depth=0):
for item in os.listdir(path):
itemWithPath = os.path.join(path, item)
if item.endswith(extension):
print item # file name only
#print itemWithPath # file name with path
#print path # path only
if os.path.isdir(itemWithPath):
findfiles(itemWithPath, extension, depth + 1)
if __name__ == '__main__':
findfiles(os.getcwd(), '.h')
|
gibt die gesuchten files aus. je nachdem welche zeilen einkommentiert sind gibt er dateiname, pfad oder beides aus.
um die dateiliste in eine textdatei zu speichern:
|
Quellcode
|
1
|
python findfiles.py > foundfiles.txt
|