Chinaunix首页 | 论坛 | 博客
  • 博客访问: 23202
  • 博文数量: 19
  • 博客积分: 1447
  • 博客等级: 上尉
  • 技术积分: 195
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-29 18:40
文章分类

全部博文(19)

文章存档

2011年(4)

2010年(15)

我的朋友
最近访客

分类: Python/Ruby

2010-12-15 08:56:24

#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"


阅读(582) | 评论(0) | 转发(0) |
0

上一篇:编写一个函数

下一篇:代码发不出去

给主人留下些什么吧!~~