I know this question has been asked (and answered) before, but it seems my situation is unique, because I cannot have any of the solution to work.
Running, I need to rename all my photos from *.JPG to *.jpg.
Let's say I don't need recursive, just all the pictures in the same folder.
The problem I meet is this one:
mv: ‘P1010521.JPG’ and ‘p1010521.jpg’ are the same fileSame problem using rename, with that kind of command:
rename 's/\.JPG$/.jpg/' *.JPG
P1020558.JPG not renamed: P1020558.jpg already exists 2 4 Answers
It is really simple:
Rename to something else than the same value with different case
rename 's/\.JPG$/\.jpgaux/' *.JPGNow rename that something else to
.jpgback again, but lowercase this timerename 's/\.jpgaux$/\.jpg/' *.jpgaux
Demo:
Source: How to change extension of multiple files from command line? Thanks to Chakra!
11really easy with mmv:
sudo apt install mmv
mmv \*.JPEG \#1.jpeg If αғsнιη is right in his comment, and I think he is, OP's problem is that a similarly named file already exists. If that is the case, the script will have to check if the targeted file name (lowercase) already exists, and (only) if so, rename the original file additionally (not only lowercase extension) to prevent the name error, e.g.
image1.JPGto
renamed_image1.jpgsince image1.jpg would raise an error
If so, a python solution to rename could be:
#!/usr/bin/env python3
import os
import shutil
import sys
directory = sys.argv[1]
for file in [f for f in os.listdir(directory) if f.endswith(".JPG")]: newname = file[:file.rfind(".")]+".jpg" if os.path.exists(directory+"/"+newname): newname = "renamed_"+newname shutil.move(directory+"/"+file, directory+"/"+newname)The script renames:
image1.JPG -> image1.jpgbut if image1.jpg already exists:
image1.JPG -> renamed_image1.jpg###How to use
Copy the script into an empty file, save it as rename.py, make it executable and run it by the command:
<script> <directory_of_files> 10 This works best I think, as perl supports running code in the regex
rename -n 's/(\.[A-Z]+$)/lc($1)/ge' *.*[A-Z]*
remove the -n to actually rename the files