Last active
March 20, 2019 00:14
-
-
Save pca2/d1357d80a113cf8e68c2186c224e0593 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, re, glob | |
#get file list | |
with open('order.txt') as file: | |
titles = file.readlines() | |
#remove \n | |
for index, item in enumerate(titles, start=0): | |
titles[index] = item.rstrip() | |
for num, title in enumerate(titles, start=1): | |
glob_result = glob.glob("*{}*".format(title.rstrip())) | |
if bool(glob_result) & bool(num > 20): | |
matched_result = glob_result[0] | |
if re.match(r'(^\d)', matched_result): | |
continue | |
print("{} begins with \d skipping".format(matched_result)) | |
new_filename = re.sub(r'(^)',"{} - ".format(num),matched_result) | |
os.rename(matched_result, new_filename) | |
print(new_filename) | |
else: | |
print(("{} - {} : glob failed, skipping").format(num, title)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment