python判断文件是否存在目录中
2024-09-02 04:45:30
##支持排除文件和目录
#!/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
最新文章
- python成长之路【第九篇】:网络编程
- 第 29 章 CSS3 弹性伸缩布局[中]
- WPF学习之路(五) 实例:写字板
- Java基本运算符
- Javascript基础系列之(六)循环语句(break和continue语句)
- 【BZOJ 2809】 [Apio2012]dispatching
- Oracle数据库导出
- 【javascript 函数基础知识】
- 【转】Android Camera(五)使用Camera功能 AREA的理解
- zookeeper_03:Java 客户端(原生API)
- python实现进度条
- win10环境下python3.5安装步骤
- Codeforces Round #509 (Div. 2)
- artTemplate/template.js模板将时间戳格式化为正常的日期
- spring和jdbctemplate
- .NET内存管理、垃圾回收
- Go语言学习之路(持续更新中)
- 微软职位内部推荐-Senior NLP Scientist
- Hadoop生态圈-Azkaban实战之Command类型多job工作流flow
- 通过修改EIP寄存器实现32位程序的DLL注入
热门文章
- 【LeetCode刷题】SQL-Combine Two Tables
- MapReduce 编程模板
- Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)
- [SHOI2009] 交通网络
- 【分块】【树状数组】bzoj3787 Gty的文艺妹子序列
- 在Code First中自动创建Entity模型
- UITextField的returnkey点击事件
- win10 关键错误开始菜单和cortana无法工作 的问题
- Bootstrap响应式布局
- Android Studio Emulator 提示 “/dev/kvm is not found” 解决办法