Python代码

。。。。  判断一个文件夹内是否存在某个文件,如果是则删除或移走(给用户提示)。 注:“某个文件”是指ArcGis中的文件,所以代码尽量接近ArcGis,当然不接近也行。

#!/usr/bin/env python
#coding=gbk
import os
import sys
import shutil
DIRNAME = "E:\Program Files\ArcGis\"#目录名称
TARGET = "C:\"#移动文件的目标目录
ISFILE = "file.txt"
if os.path.isfile(DIRNAME+ISFILE):
try:
i = raw_input("Move file %s ? [Y/N] " %ISFILE)
if 'y'==i.lower():
shutil.move(DIRNAME+ISFILE,TARGET+ISFILE)
elif 'n'==i.lower():
pass
else:
print "Please input 'Y' or 'N'"
except KeyboardInterrupt:# catch CTRL-C
print "exit!"
sys.exit(1)
else:
print "File %s%s doesn't exists !" %(DIRNAME+ISFILE)

原文地址:https://www.cnblogs.com/ryyy/p/14239498.html