Skip to content

Instantly share code, notes, and snippets.

@nari-ex
Created Feb 9, 2015
Embed
What would you like to do?
大量のファイルを移動するスクリプト
#!/usr/bin/env python
# coding: utf-8
import os
import time
src_dir = ""
dst_dir = ""
import_file = ""
export_file = ""
if __name__ == '__main__':
file_list = open(import_file, 'r')
result_file = open(export_file, 'w')
for count, line in enumerate(file_list.readlines()):
filename = line.lstrip('./').rstrip('\r\n')
src_file = os.path.join(src_dir, filename)
if not os.path.exists(src_file):
result_file.write(line)
else:
dst_file = os.path.join(dst_dir, filename)
if not os.path.exists(dst_file):
os.rename(src_file, dst_file)
if count % 100 == 0:
time.sleep(0.1)
result_file.close()
file_list.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment