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 写入文件后需要重新打开一次文件进行读取这个坑。