您的位置:首页 > 其它

常用脚本之本件

2016-02-02 00:00 197 查看
#coding=utf-8
'''
Created on Nov 27

@author:tianmaxingkongdeyu

'''

import os
import time

def nsfile(s):
'''The number of new expected documents'''
#判断文件夹是否存在,如果不存在则创建
b = os.path.exists("C:\\testFile\\")
if b:
print "File Exist!"
else:
os.mkdir("C:\\testFile\\")
#生成文件
for i in range(1,s+1):
localTime = time.strftime("%Y%m%d%H%M%S",time.localtime())
#print localtime
filename = "C:\\testFile\\"+localTime+".txt"
#a:以追加模式打开(必要时可以创建)append;b:表示二进制
f = open(filename,'ab')
testnote = '测试文件600'
f.write(testnote)
f.close()
#输出第几个文件和对应的文件名称
print "file"+" "+str(i)+":"+str(localTime)+".txt"
time.sleep(1)
print "ALL Down"
time.sleep(1)

if __name__ == '__main__':
s = input("请输入需要生成的文件数:")
nsfile(s)

if __name__=="__main__":
s = input("请输入需要生成的文件数:")
nsfile(s)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: