配置文件config.ini
[global]
#原文件存放目录
dir1=F:\work\python\3595\pyserver\test
#新文件存放目录
dir2=F:\work\python\3595\pyserver\test1
python代码
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,ConfigParser,time
class file_openate(object):
def __init__(self):
#初如化读取数据库配置
dir_config = ConfigParser.ConfigParser()
file_config=open('config.ini',"rb")
dir_config.readfp(file_config)
self.dir1=str(dir_config.get("global","dir1"))
self.dir2=str(dir_config.get("global","dir2"))
self.dir2=unicode(self.dir2,'utf8')
self.dir1=unicode(self.dir1,'utf8')
#print self.dir2
#self.dir2=self.dir2.unicode(os.path.join(os.path.dirname(__file__),'CtManage','templates').replace('\\','/'),"gb2312")
file_config.close()
#数据库连接
def file_list(self):
input_name_han="请输入需要移多少文件:".decode('utf-8')
while 1:
input_name=raw_input("number:")
input_name=str(input_name)
#print input_name
if input_name.isdigit():
input_name=int(input_name)
i=0
for filename in os.listdir(self.dir1):
i=i+1
if i <= input_name:
os.rename(self.dir1+'/' +filename,self.dir2 +'/' +filename)
print filename+"成功".decode('utf-8')
else:
print "请输入正确的数字".decode('utf-8')
file_name=file_openate()
file_name.file_list()