python创建和删除⽂件#!/usr/bin/python
#-*-coding:utf-8-*- #指定编码格式,python默认unicode编码
import os
directory = "./dir"
茯神的功效与作用及食用方法os.chdir(directory) #切换到directory⽬录
cwd = os.getcwd() #获取当前⽬录即dir⽬录下
print("------------------------current working directory------------------")
def deleteBySize(minSize):
五个字的网名大全"""删除⼩于minSize的⽂件(单位:K)"""
files = os.wd()) #列出⽬录下的⽂件
for file in files:
if size(file) < minSize * 1000:
print(file + " deleted")
return
def deleteNullFile():
'''删除所有⼤⼩为0的⽂件'''
files = os.wd())
for file in files:
如何下载歌曲if size(file) == 0: #获取⽂件⼤⼩
print(file + " deleted.")
return
def create():
6.1祝福语'''根据本地时间创建新⽂件,如果已存在则不创建'''
import time
t = time.strftime('%Y-%m-%d',time.localtime()) #将指定格式的当前时间以字符串输出
suffix = ".docx"
newfile= t+suffix
if not ists(newfile):
f = open(newfile,'w')
print newfile
f.close()
print newfile + " created."
else:
print newfile + " already existed."
return
hint = '''funtion:
1 create new file
草原之夜歌词2 delete null file
3 delete by size
please input number:'''
while True:
option = raw_input(hint) #获取IO输⼊的值
if cmp(option,'1') == 0:
create()
elif cmp(option,'2') == 0:
deleteNullFile()
elif cmp(option,'3') == 0:
minSize = raw_input("minSize(K):")
deleteBySize(minSize)
elif cmp(option,'q') == 0:
print "quit !"
break
else:
print ("disabled input ,please ")
>手机怎么扫描二维码
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论