-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirWalk.py
30 lines (26 loc) · 911 Bytes
/
dirWalk.py
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
30
#!/usr/bin/env python
#Author: Mike R
#walking the current working directory
import os
i=0
dash='---'
#ask user for directory or take it.
def dirWalk(thisDir, dash, i):
i=i+1
for item in os.listdir(thisDir):
fullPath=os.path.join(thisDir,item)
if os.path.isfile(fullPath):
print (dash*i) + item
print os.stat(fullPath) #get file information
elif os.path.isdir(fullPath):
print (dash*i) + item
newDir=thisDir + "/" + item
dirWalk(newDir, dash, i)
else:
print "unknown!"
#see if there is a way to print the directory name, not necessarily full path
directory=raw_input("What directory do you want to walk: ")
#if one wanted to get all files, then one would need to be sudo
#This would be used if one wanted to walk current directory
#curDir=os.getcwd()
dirWalk(directory, dash, i)