[Tutor] Comments appreciated
Luis N
tegmine at gmail.com
Wed Dec 22 02:06:22 CET 2004
This is the most meaningful thing this newbie has ever done. Comments
are appreciated:
#!/usr/local/bin/python
trashcan = "/home/anewby/.trashcan"
import os, sys, shutil
junk = []
for arg in sys.argv:
junk.append(arg)
junk = junk[1:]
empty = False
if "-e" in junk:
empty = True
junk.remove("-e")
if not os.path.exists(trashcan):
os.mkdir(trashcan)
def trash(junk):
for i in junk:
toss = trashcan + "/" + i
if os.path.exists(toss):
if os.path.isdir(toss):
shutil.rmtree(toss)
if os.path.isfile(toss):
os.remove(toss)
os.rename(i, toss)
def can():
for j in os.listdir(trashcan):
if os.path.isdir(j):
shutil.rmtree(j)
if os.path.isfile(j):
os.remove(j)
if len(junk) is 0 and empty == False:
sys.exit()
else:
if len(junk) > 0:
trash(junk)
if empty == True:
can()
More information about the Tutor
mailing list