Verzeichnis rekursiv durchsuchen

ID70
Link ReferenceNot set
Link CreditsNot set
Link Technical DocumentationNot set
PlCodelangPython
PlGroupFilehandling
PlItemTitleVerzeichnis rekursiv durchsuchen
Codeimport os

searchPath = '/home/patrick/Desktop/'

# os.walk will go through all subdirectories
for pathentry in os.walk(searchPath, False):
for dir in pathentry[1]:
path = os.path.join(pathentry[0], dir)
if os.path.islink(path):
print path + "... is a link"
# os.unlink(path)
else:
print path + "... is a dir"
# os.rmdir(path)

for file in pathentry[2]:
path = os.path.join(pathentry[0], file)
# os.unlink(path)
print path + "... is a file"


# os.listdir only the given path
for file in os.listdir(searchPath):
fullfilename = os.path.join(searchPath, file)
if os.path.isfile(fullfilename):
print fullfilename + "... is a file"
Result Example