Created
October 17, 2021 01:58
-
-
Save kujiy/ff7cd0bb63049dfebf8e075ff224a9f6 to your computer and use it in GitHub Desktop.
Rename files in dirs with the dir names
This file contains hidden or 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
""" | |
# rename files in dirs | |
current_dir | |
|- dir1 | |
|- 001.jpg | |
|- 002.jpg | |
|- dir2 | |
|- 001.jpg | |
|- 002.jpg | |
Convert to | |
current_dir | |
|- dir1-001.jpg | |
|- dir1-002.jpg | |
|- dir2-001.jpg | |
|- dir2-002.jpg | |
""" | |
import os | |
li = os.listdir(".") | |
for d in li: | |
print(d) | |
if os.path.isdir(d): | |
files = os.listdir(f"{d}") | |
for f in files: | |
print(f"{d}-{f}") | |
os.rename(f"{d}{f}", f"{d}-{f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go-lang version
https://github.com/kujiy/go-rename