Skip to content

Instantly share code, notes, and snippets.

@pinfort
Created September 25, 2017 08:37
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 pinfort/b69a28475b518280d87f20f623701d61 to your computer and use it in GitHub Desktop.
Save pinfort/b69a28475b518280d87f20f623701d61 to your computer and use it in GitHub Desktop.
ファイル移動
# -*- coding: utf-8 -*-
import os
import shutil
import sys
path = '/mnt/hdd1/nas/picture/smartphone/rei/20170909/pictures/Twitter'
files = os.listdir(path)
# ファイル移動
# for file in files:
# lis = file.split('_')
# if len(lis) == 3:
# if not os.path.isdir('/mnt/hdd1/nas/picture/smartphone/rei/20170909/pictures/Twitter/' + lis[1]):
# os.mkdir('/mnt/hdd1/nas/picture/smartphone/rei/20170909/pictures/Twitter/' + lis[1])
# shutil.move('/mnt/hdd1/nas/picture/smartphone/rei/20170909/pictures/Twitter/' + file, '/mnt/hdd1/nas/picture/smartphone/rei/20170909/pictures/Twitter/' + lis[1] + '/' + file)
# print(file + ' moved to ' + lis[1] + '/' + file)
# sys.exit()
# ディレクトリ移動
for file in files:
if not os.path.isdir(os.path.join(path, file)):
continue
if not len(file) == 8:
continue
newdir = file[0:6]
if not os.path.isdir(os.path.join(path, newdir)):
os.mkdir(os.path.join(path, newdir))
shutil.move(os.path.join(path, file), os.path.join(os.path.join(path, newdir), file))
print(file + 'moved to ' + os.path.join(newdir, file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment