Verzeichnis rekursiv durchsuchen
ID | 70 |
---|---|
Link Reference | Not set |
Link Credits | Not set |
Link Technical Documentation | Not set |
PlCodelang | Python |
PlGroup | Filehandling |
PlItemTitle | Verzeichnis rekursiv durchsuchen |
Code | import 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 |