发布于2019-08-17 20:44 阅读(672) 评论(0) 点赞(0) 收藏(1)
import os
store_file = 'E:'
old_content_path = store_file + "old.txt"
new_content_path = store_file + "new.txt"
copy_content_path = store_file + "copy.txt"
old_content_file = open(old_content_path, 'w+') #储存需要备份的文件内容
new_content_file = open(new_content_path, 'w+') #储存已备份文件夹中的内容
copy_content_file = open(copy_content_path, 'w+') #储存需要复制的内容
old_path = 'E:\\Honor数据备份\\Pictures\\iphone'
new_path = 'E:\\Honor数据备份\\Pictures'
def readFileList(path,filename):
for (root,dirs,files) in os.walk(path):
for every_root in root:
for every_files in files:
filename.write(str(root)+'\\'+str(every_files)+'\n')
print('完成文件写入')
readFileList(old_path,old_content_file)
readFileList(new_path,new_content_file)
old_content = old_content_file.readlines()
new_content = new_content_file.readlines()
old_content_file.close()
new_content_file.close()
print(new_content)
print(old_content)
完成文件写入
完成文件写入
[]
[]
PS D:\Project\SyncPhoto>
结果读取出来的数组全为空。
思考一番,我猜想,怕不是需要重新打开一次文件?然后就试了一下。
import os
copy_file =[[],[],[]]
store_file = 'E:'
old_content_path = store_file + "old.txt"
new_content_path = store_file + "new.txt"
copy_content_path = store_file + "copy.txt"
old_content_file = open(old_content_path, 'w') #储存需要备份的文件内容
new_content_file = open(new_content_path, 'w') #储存已备份文件夹中的内容
copy_content_file = open(copy_content_path, 'w') #储存需要复制的内容
old_path = 'E:\\Honor数据备份\\Pictures\\iphone'
new_path = 'E:\\Honor数据备份\\Pictures'
def readFileList(path,filename):
for (root,dirs,files) in os.walk(path):
for every_root in root:
for every_files in files:
filename.write(str(root)+'\\'+str(every_files)+'\n')
print('完成文件写入')
readFileList(old_path,old_content_file)
readFileList(new_path,new_content_file)
old_content_file.close()
new_content_file.close()
old_content_file = open(old_content_path, 'r') #储存需要备份的文件内容
new_content_file = open(new_content_path, 'r') #储存已备份文件夹中的内容
old_content = old_content_file.readlines()
new_content = new_content_file.readlines()
print(new_content)
就填上了python 写入文件后需要重新打开一次文件进行读取这个坑。
作者:黎明要到来了
链接:https://www.pythonheidong.com/blog/article/48429/922474c87cacdcbe5988/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!