#Delete all files under the pointed path
import os
filePath = raw_input("Input path where you want delete:\n")
#If file path is null, we should initial the variable "/home"
if filePath == "":
filePath = "/home"
#Obtain the path or file under the filePath and restore in list named paths
def obtainPath(path):
try:
print path
paths = os.listdir(path)
except:
print "Obtain the path or file occured an error!"
return paths
#Inith list paths and root path
initialPaths = obtainPath(filePath)
initialRoot = filePath
#Do loop to search file and then delete
def loopDelete(initialPaths, initialRoot):
while len(initialPaths) > 0:
for temp in initialPaths:
tempPath = initialRoot + '/' + temp
initialPaths.remove(temp)
if os.path.isfile(tempPath):
os.remove(tempPath)
else:
loopDelete(obtainPath(tempPath), tempPath)
#Invoke the loop delete way to excute
loopDelete(initialPaths, initialRoot)