Created
September 25, 2017 08:37
-
-
Save pinfort/b69a28475b518280d87f20f623701d61 to your computer and use it in GitHub Desktop.
ファイル移動
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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