我正在寻找一个python脚本,例如前5000个文件并将它们复制到另一个文件夹。然后在另一次运行之后,将接下来的5000个文件并复制它们。
我尝试使用shutil
,但不管我做了什么都无法使它工作。
你能帮忙,还是指导我正确的方向?
这应该为您阅读代码以获得帮助以使其工作将Mkv格式更改为您想要的任何内容
这是一个python脚本,你可以使用crontab for Linux或Microsoft windows schedule工具,如果你需要任何帮助只需回复
import os
import json
SRC_FOLDER = '/home/SOURCE /'
DEST_FOLDER = '/home/Destination folder /'
def read_data():
with open('/home/PATH TO the json file.json') as f:
data = json.load(f)
return data
def write_data(added_files, uploaded_files):
with open('/home/PATH TO the json file.json', 'w') as f:
json.dump(added_files+uploaded_files, f)
def main():
all_downloads = os.listdir(SRC_FOLDER)
all_uploads = read_data()
added_files = []
for file_name in all_downloads:
if file_name not in all_uploads:
if "mkv" == file_name.split(".")[-1]:
print file_name.split('.')[-1]
added_files.append(file_name)
file = open(DEST_FOLDER+file_name, 'wb')
with open(SRC_FOLDER+file_name, 'rb') as f:
while True:
byte = f.read(20480)
if not byte:
break
file.write(byte)
write_data(added_files, all_uploads)
if __name__ == '__main__':
main()
iCODEiT 0UT