import os
""" Print files recursively in a tree"""
path_dir = raw_input("Enter the directory path: ")
for root, subdirs, files in os.walk(path_dir):
level=" "*len(root.split("\\"))
print "%s|_ %s" %(level,root)
if subdirs:
pass
if files:
for file in files:
print "%s|___ %s" %(level, file)
else:
pass
""" Print files recursively in a tree"""
path_dir = raw_input("Enter the directory path: ")
for root, subdirs, files in os.walk(path_dir):
level=" "*len(root.split("\\"))
print "%s|_ %s" %(level,root)
if subdirs:
pass
if files:
for file in files:
print "%s|___ %s" %(level, file)
else:
pass
Output:
C:\Program Files (x86)>C:\Python27\python.exe D:/Deepti/Work/Python/practice/recursive_dir.py
Enter the directory path: D:\Deepti\Work\Python\practice\Dir
|_ D:\Deepti\Work\Python\practice\Dir
|_ D:\Deepti\Work\Python\practice\Dir\dir1
|___ text11.txt
|___ text12.txt
|_ D:\Deepti\Work\Python\practice\Dir\dir1\dir11
|___ text111.txt
|___ text112.txt
|_ D:\Deepti\Work\Python\practice\Dir\dir1\dir12
|___ fiel122.txt
No comments:
Post a Comment