#encoding=utf-8 import os #输入要查看的目录名,如“e:ArcGis” inputdir = raw_input("input:") print os.listdir(inputdir)
#输入要删除的文件或者目录名 inputtodelete = raw_input("file to delete:")
#如果是目录,则进行循环删除 if os.path.isdir(inputtodelete): for root, dirs, files in os.walk(inputdir + os.sep + inputtodelete,topdown=False): for file in files: os.remove(os.path.join(root,file)) for dir in dirs: os.rmdir(os.path.join(root,dir)) os.rmdir(inputdir + os.sep + inputtodelete) print"dir deleted!" #是文件,则直接删除 elif os.path.isfile(inputtodelete): os.remove(inputdir+os.sep+inputtodelete) print"file deleted!" else: print"error!not file or dir"