Add the extension, jpg, to a lot of files
9,315
Solution 1
I did it this way
find . -type f -iregex ".*[^\(\.jpg\)]" -exec mv "{}" "{}.jpg" ";"
Solution 2
You can do it through cmd on windows.
rename * *.jpg
Edit:
To apply to nested folders, you can use;
for /r %x in (*) do rename "%x" *.jpg
Solution 3
If using powershell is an option, then this post from SO should be exactly what you want.
Solution 4
On Linux
ls | while read file ; do mv $file $file.jpg; done
On Windows
I like to use Rename4u which is a freeware utility.
Related videos on Youtube
Author by
Kurru
You can find my blog at https://pupeno.com where I publish about coding and other stuff.
Updated on September 17, 2022Comments
-
Kurru over 1 year
I have a folder with a lot of folders with a lot of files and maybe more folders with more files, where some files lost their extension. I believe they are all jpgs, but I could be wrong. Any ideas how to re-add the extensions to all these files without doing it one by one?
I can do it on Windows 7 or Ubuntu 8.10.
-
Gnoupi over 14 yearsThis question will probably have an answer for you, as it is a bit similar : superuser.com/questions/16007/…
-
ChrisF over 14 yearsDid you check that you haven't turned off the display of the extension on those folders before embarking on the rename? Basic question I know, but you never know.
-
-
Jeffrey over 14 yearsJust got to be careful not to append a .jpg extension to IMAGE001.jpg
-
Kurru over 14 yearsWouldn't the Linux version add the extension to all the files? Not all the files are missing the extension.
-
Kurru over 14 yearsWill that work recursively in all folders?
-
Stewbob over 14 yearsThe command prompt still has its uses :) Yeah DOS!
-
Jeffrey over 14 yearsIt will not - you'll need to use the 'for' command as demonstrated here: stackoverflow.com/questions/210413/…
-
RJFalconer over 14 yearsThanks Jeffrey; I've not come across "for" before! That's pretty nifty. I added that to the solution body.
-
UNK over 14 years@J Pablo, .jpg.jpg still opens as a jpg ;) In windows I'd do: ren * *.jpg but you could hack something together with a batch file to only do that if something didn't have an extension - I'm too lazy, myself. If it works, it works, right?
-
Joey over 14 years+1 for a nice answer that didn't involve installing other operating systems or a heap of other programs.
-
NVRAM over 14 yearsNice. FWIW, a simpler method than -iregex is to use the negative of a name match: find . -type f \! -name '.jpg' (...). Also, I try always to use an absolute path (*/bin/mv) when using find/-exec.