Ok i need some help here people...
I have 30k+ images without extensions...
I used a program called GPRename to give each of my images a random name, because some of the names were very long so they were causing problems, and it deleted the file extension on all my pictures now I'm having difficulty opening the images on my windows computer and my phone (no prob on linux)
I was wondering if any of you know of a program/script I can use that would add the correct file extension to the end of all the images
I was thinking of a script using the bash command "file" but i'm not very good with bash so I would have no idea how to do this for multiple files
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Bash Script Help Please...
Re: Bash Script Help Please...
Try the following code in a copy of one of your directories containing the extensionless files.
Code: Select all
for f in *; do mv -v "$f" "$f.$( ( file "$f" | cut -s -d\: -f 2 | cut -s -d\ -f 2 | tr [:upper:] [:lower:] ) )";done
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan
Re: Bash Script Help Please...
If all the extensions were the same as in (.JPG, .jpg, etc...) you could add that extension back easy enough.ilovepoker wrote: I was wondering if any of you know of a program/script I can use that would add the correct file extension to the end of all the images
Example of before renaming:
Code: Select all
$ ls
imagefile1.jpg imagefile2.jpg
Code: Select all
$ ls
NEWNAME1 NEWNAME2
Code: Select all
for old in *; do mv $old `basename $old `.jpg; done;
Code: Select all
$ ls
NEWNAME1.jpg NEWNAME2.jpg
Jessie/Xfce