Skip to content

Instantly share code, notes, and snippets.

@nari-ex
Created February 9, 2015 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nari-ex/4a95aa049ebfe0b2afd1 to your computer and use it in GitHub Desktop.
Save nari-ex/4a95aa049ebfe0b2afd1 to your computer and use it in GitHub Desktop.
大量のファイルを移動するスクリプト
#!/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