Last active
June 2, 2018 15:59
-
-
Save teionn/fceaf0bfd99e7fa425bf46f0d93f566c 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
#ファイル名に (<数字>) がついてしまったものを元に戻す。 | |
#オリジナルが存在したら複製は消す。 | |
#日付は見ていないので注意 | |
import os | |
import re | |
def find_all_files(directory): | |
for root, dirs, files in os.walk(directory): | |
yield root | |
for file in files: | |
yield os.path.join(root, file) | |
_path="" | |
_data=find_all_files(_path) | |
for _file in _data: | |
_path,_name=os.path.split(_file.replace("\\","/")) | |
_search=re.search(" \(\d\)$", os.path.splitext(_name)[0]) | |
if not _search is None : | |
_orgName="%s/%s" % (_path,_name.replace(_search.group(),"")) | |
if os.path.exists(_file): | |
if os.path.exists(_orgName): | |
print "delete : ",_file | |
os.remove(_file) | |
else: | |
print "rename : ",_file | |
os.rename(_file,_orgName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment