Python文件复制,备份,搜索
来源:互联网 发布:adsafe mac版 编辑:程序博客网 时间:2024/06/06 05:19
#文件的复制'''def copy(): source = input("请输入文件位置:") target = input("请输入要复制文件的位置:") old_file = open(source, "br") new_file = open(target, "bw") content = old_file.read() new_file.write(content) old_file.close() new_file.close()copy()''''''#复制传递大文件def copy(): source = input("请输入文件名:") target = input("请输入储存位置:") old_file = open(source, "br")f: new_file = open(target, "bw") while True: content = old_file.read(1024 * 1024) if content: #if content content不为空 开始复制,为空结束 new_file.write(content) else: print("文件复制完成!") break old_file.close() new_file.close()copy()'''#加备份'''def back_file(): file_name = input("请输入与您要备份的文件名称:") # new_name = input("亲输入备份名称:") # 获取文件的后缀名称 sep = file_name.rindex("/") dir = file_name[:sep + 1] name = file_name[sep + 1:] new_file_name = dir + "[备份]" + name old_file = open(file_name, "br") new_file = open(new_file_name, "bw") with open(file_name, "br") as f: while True: content = old_file.read(1024 * 1024) if content: # if content content不为空 开始复制,为空结束 new_file_name.write(content) else: print("文件复制完成!") break old_file.close() new_file.close()#程序入口back_file()'''#查询指定目录下的搜有文件"""import osdef list_file(path): child_file = os.listdir(path) for file in child_file: if os.path.isfile(path + "/" + file): print("这是一个文件:%s" % file) else: print(" %s" % (path + "/" + file)) list_file(path + "/" + file)list_file("F:\代码\.metadata")"""#指定目录下搜索文件import osimport sysdef search(path, word): for filename in os.listdir(path): fp = os.path.join(path, filename) if os.path.isfile(fp) and word in filename: print(fp) elif os.path.isdir(fp): search(fp, word)search("F:\软件测试","14云计算")#前为搜索的位置,后为要搜索的文件的部分信息
阅读全文
0 0
- Python文件复制,备份,搜索
- Python实现文件备份
- Python 创建文件备份
- python 文件增量备份
- Python实现文件备份
- python实践,文件备份
- Python 复制文件操作
- Python复制文件
- python文件操作--复制
- python 复制文件
- python复制文件
- Python 复制移动文件
- python文件复制机
- Python与文件搜索
- Python搜索文件
- 用复制命令做文件异地备份
- Python库文件地址备份
- Python 备份指定目录文件
- 交换两个数的值
- GridView、ListView数据更新图片闪烁问题
- pythonWeb -- Django开发-视图层开发和URL配置
- 2017.7.24 未做完的题目
- Java开发必会的Linux命令
- Python文件复制,备份,搜索
- 机器学习update操作总结
- JS、html、css注释方式及作用
- poj 1002 487-3279之map解法
- Codis源码解析——dashboard的启动(2)
- 关于java中Double类型的运算精度问题(转)
- HDU5288:OO’s Sequence(思维)
- YUV420如何扣取指定区域的图像数据
- ZOJ 3769 (分组背包)