-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a5a173
commit 7a8e812
Showing
4 changed files
with
48 additions
and
31 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import os | ||
|
||
|
||
def main(): | ||
img_types = ['jpg', 'png', 'jpeg'] | ||
img_types = ["jpg", "png", "jpeg"] | ||
dir_path = input("Enter the directory path of the images: ") | ||
|
||
for i, f in enumerate(os.listdir(dir_path)): | ||
absname = os.path.join(dir_path, f) | ||
img_type = absname.split('.')[-1] | ||
img_type = absname.split(".")[-1] | ||
|
||
if img_type in img_types: | ||
while True: | ||
newname = input(f"Enter the new name for {f} (without extension): ") | ||
newname = '{}.{}'.format(newname, img_type) | ||
newname = "{}.{}".format(newname, img_type) | ||
new_absname = os.path.join(dir_path, newname) | ||
if not os.path.exists(new_absname): | ||
os.rename(absname, new_absname) | ||
break | ||
else: | ||
print("A file with this name already exists. Please enter a different name.") | ||
print( | ||
"A file with this name already exists. Please enter a different name." | ||
) | ||
|
||
print("Done renaming images.") | ||
|
||
print('Done renaming images.') | ||
|
||
if __name__ == "__main__": | ||
main() |
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
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