Created
August 1, 2020 13:40
-
-
Save xAlpharax/5da6c016b1cd4dc83dac87afd0f334da to your computer and use it in GitHub Desktop.
Rename same filenames from entire directory
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 filecmp | |
dirnow = os.getcwd() | |
print("Now in: {} \n".format(dirnow)) | |
names_seen = list() | |
def renamestuff(path): | |
n = 1 | |
for root, dirs, files in os.walk(path): | |
for name in files: | |
filePath = os.path.join(os.path.abspath(root), name) | |
if n == 20: | |
n = 1 | |
if name.lower() in names_seen: | |
newname = name.replace('.', ' ({}).'.format(n)) | |
os.rename(filePath, os.path.join(os.path.abspath(root), newname)) | |
n += 1 | |
# names_seen.append(newname) | |
else: | |
names_seen.append(name) | |
n = 1 | |
print(name) | |
return | |
renamestuff(os.path.join(dirnow, 'dir')) | |
print('\n', names_seen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment