-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiditwork.py
32 lines (27 loc) · 980 Bytes
/
diditwork.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
31
32
#!/usr/bin/python
from optparse import OptionParser
import subprocess
import os,sys
options,args = None, None
p = OptionParser()
p.add_option("-r","--remove",action="store_true",dest="remove",help="if -r then directories are removed")
if len(sys.argv) == 1:
p.print_help()
try:
options,args = p.parse_args()
except IndexError:
p.print_help()
are_you_sure = "No"
confirmation_received = None
cwd = os.getcwd()
for root,dirs,files in os.walk(cwd):
for adir in dirs:
if not options.remove:
print ("Directory:%s" % adir)
subprocess.call(["ls" ,"-ltr",os.path.join(root,adir)])
if options.remove:
if are_you_sure == "No" and confirmation_received is None:
are_you_sure = raw_input("Are you SURE(Yes/No):")
confirmation_received = True
if are_you_sure == "Yes":
subprocess.call(["rm" , "-rf" ,os.path.join(root,adir)])