##支持排除文件和目录
#!/usr/bin/python
#coding:utf-8
import os def list_file(file_name):
data = []
file_name = file_name
with open(file_name,'r') as f:
for line in f.readlines():
line = line.strip('\n')
data.append(line)
return data def list_dir(dir_name):
data = []
dir_name = dir_name
for root,dirs,files in os.walk(dir_name):
#exclude.txt写入需要排除比较的目录
for rdir in open("./exclude.txt"):
rdir = rdir.strip('\n')
if rdir in dirs:
dirs.remove(rdir)
#print dirs
for filename in files:
filepath = os.path.join(root,filename)
#f.write(filepath+'\n')
data.append(filepath)
return data
if __name__ == "__main__":
keep_file = 'file.txt'
local_dir = '/opt/app/fileops/testdir/'
keep_path = list_file(keep_file)
local_path = list_dir(local_dir)
for i in local_path:
if i not in keep_path:
#print os.path.getctime(i)
#os.remove(i)
print i

最新文章

  1. python成长之路【第九篇】:网络编程
  2. 第 29 章 CSS3 弹性伸缩布局[中]
  3. WPF学习之路(五) 实例:写字板
  4. Java基本运算符
  5. Javascript基础系列之(六)循环语句(break和continue语句)
  6. 【BZOJ 2809】 [Apio2012]dispatching
  7. Oracle数据库导出
  8. 【javascript 函数基础知识】
  9. 【转】Android Camera(五)使用Camera功能 AREA的理解
  10. zookeeper_03:Java 客户端(原生API)
  11. python实现进度条
  12. win10环境下python3.5安装步骤
  13. Codeforces Round #509 (Div. 2)
  14. artTemplate/template.js模板将时间戳格式化为正常的日期
  15. spring和jdbctemplate
  16. .NET内存管理、垃圾回收
  17. Go语言学习之路(持续更新中)
  18. 微软职位内部推荐-Senior NLP Scientist
  19. Hadoop生态圈-Azkaban实战之Command类型多job工作流flow
  20. 通过修改EIP寄存器实现32位程序的DLL注入

热门文章

  1. 【LeetCode刷题】SQL-Combine Two Tables
  2. MapReduce 编程模板
  3. Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)
  4. [SHOI2009] 交通网络
  5. 【分块】【树状数组】bzoj3787 Gty的文艺妹子序列
  6. 在Code First中自动创建Entity模型
  7. UITextField的returnkey点击事件
  8. win10 关键错误开始菜单和cortana无法工作 的问题
  9. Bootstrap响应式布局
  10. Android Studio Emulator 提示 “/dev/kvm is not found” 解决办法