Python代码如下:

import os
directory = "E:\\学习日志\\"
os.chdir(directory) # 改变当前工作目录
cwd = os.getcwd() # 查看当前工作目录
print("--------------current working directory : " + cwd + "----------") def deleteBySize(minSize):
"""删除小于minSize的文件(单位:K)"""
files = os.listdir(os.getcwd()) # 列出目录中文件
for file in files:
## print file + " : " + str(os.path.getsize(file))
if os.path.getsize(file) < minSize * 1000:
os.remove(file)
print(file + " deleted.")
return def deleteNullFile():
'''删除所有大小为0的文件'''
files = os.listdir(os.getcwd()) # 列出目录中文件
for file in files:
if os.path.getsize(file) == 0: #得到文件大小,如果是目录返回0
os.remove(file)
print(file + " deleted")
return def create():
'''根据本地时间创建新文件,如果已存在则不创建'''
import time
#将指定的struct_time(默认为当前时间),根据指定的格式化字符串输出
t = time.strftime('%Y-%m-%d',time.localtime())
suffix = ".docx"
newFile =os.getcwd() + "\\" + t + suffix
if not os.path.exists(newFile):
f = open(newFile,'w')
f.close()
print newFile + " created."
else:
print newFile + " already exist."
return hint = '''funtion :
1 create new file
2 delete null file
3 delete by size
q quit\n
please input number: '''
while True:
option = raw_input(hint)
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 try again...")

主要涉及到的就是一些文件操作函数和时间函数。

最新文章

  1. CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
  2. 部署点评Cat监控项目(转)
  3. 提高sevenzipsharp 检查密码的速度(1)
  4. EasyUI 验证框使用方法
  5. 当数据0跟if判断冲突的时候
  6. PCL—低层次视觉—关键点检测(NARF)
  7. Struts2的简单案例
  8. JDBC获取表的主键
  9. PB11.5创建及调用WebService
  10. LoadRunner监控数据库服务器
  11. Mac OSX操作系统安装和配置Zend Server 6教程(3)
  12. Being a Good Boy in Spring Festival(尼姆博弈)
  13. 我与java的故事
  14. 第二阶段第七次spring会议
  15. 开发HR人事考试系统介绍
  16. Docker Registry V2 with Nginx
  17. JavaEE笔记(十一)
  18. saltops 安装及相关环境安装
  19. kotlin 类 接口 抽象类 子类类型有限的class 。sealed class
  20. Markdown 中的目录自动生成功能 TOC

热门文章

  1. windows下如何快速优雅的使用python的科学计算库?
  2. selenium3 踩坑--move_to_element()报错
  3. ASP.NET动态网站制作(11)-- JQ(3)
  4. 用nvm管理windows nodejs时用npm全局安装的插件无法调用的解决方案
  5. .NET Winform 将引用的dll文件集成到exe中(转)
  6. 九度OJ 1061:成绩排序 (排序)
  7. iOS 流布局 UICollectionView使用(UICollectionVIew的代理方法)
  8. LeetCode——Binary Tree Postorder Traversal
  9. linux下tar.xz结尾文件的解压方法
  10. HTML5_CSS3仿Google Play垂直菜单