Clean Up File Names

Cleaning up Funny File Names
Keep your Original files somewhere SAFE as a source to restart the project should it hiccup : )
Utilities Used: Google them for your Platform…
Examples are for Image Files- Suit Yourself here though.
Red is Commands- Green is My Results.

detox, exiftool, imagemagick, convmv, 

I copied a lot of cranky old 20 year old Floppy Disk image files into a Linux folder to clean up with the intention they should end up inside Apple Photos which would use their proper Image Timestamp to good effect : )

$ls -l
-rwxr-xr-x 1 sysop sysop 59993 Mar 29 2003 <A9>2002 12 19 Sunrise -5<B0> (21).jpg
-rwxr-xr-x 1 sysop sysop 78345 Mar 29 2003 <A9>2002 12 19 Sunrise -5<B0> (79).jpg
-rwxr-xr-x 1 sysop sysop 55210 Mar 29 2003 <A9>2002 12 31 Silvester (1).jpg
-rw-r--r-- 1 sysop sysop 55302 Mar 29 2003 ©2002 12 31 Silvester (2).jpg
-rwxr-xr-x 1 sysop sysop 190714 Feb 15 2003 20%20Mutterstuten%20mit%20Fohlen.jpg

Be Nice! Lets Set ’em all to reasonable Permissions:
$chmod -Rvc 644 *

This untangles ‘funny’ characters and irregularities:
$detox -r -v *

These three unify foreign language characters to standard UTF-8
(Note the final "." period meaning "Here")
$convmv -r -f windows-1252 -t UTF-8 .
$convmv -r -f ISO-8859-1 -t UTF-8 .
$convmv -r -f cp-850 -t UTF-8 .

Clean Em Up!! Lowercase names:
$for file in $(ls); do mv -i ${file} ${file,,}; done
Replace spaces in file names with underbar:
$rename ‘s/\s/_/g’ ./*.jpg

None of this so far changes the original Time Stamp on the file-
Its Creation date, only its access point: Its Name.
Which is Good. Could be useful.
Older digital Pictures did not use the EXIF metadata
that records when the Picture was taken, etc, so, this is all we have got: the File Creation Date listed by “ls -l “.

I wanted to standardize on .JPG files, as there were a mix  of GIF, BMP, etc etc.. Your choice however.
ImageMagick's MOGRIFY is good for that; Here, making all gifs into jpgs.

$mogrify -format jpg *.gif

*note* I found some animated GIFs and the result was an array of single .jpg's
as jpg does NOT have the ability to Animate! Ugh!
IE: This single file has 6 images within it. using ImageMagicks' "identify" utility.. Just a Warning...
$identify WdfAnimate.gif
WdfAnimate.gif[0] GIF 275x440 275x440+0+0 8-bit sRGB 256c 98.7KB 0.000u 0:00.000
WdfAnimate.gif[1] GIF 275x440 275x440+0+0 8-bit sRGB 256c 98.7KB 0.000u 0:00.000
WdfAnimate.gif[2] GIF 275x440 275x440+0+0 8-bit sRGB 256c 98.7KB 0.000u 0:00.000
WdfAnimate.gif[3] GIF 275x440 275x440+0+0 8-bit sRGB 256c 98.7KB 0.000u 0:00.000
WdfAnimate.gif[4] GIF 275x440 275x440+0+0 8-bit sRGB 256c 98.7KB 0.000u 0:00.000
WdfAnimate.gif[5] GIF 275x440 275x440+0+0 8-bit sRGB 256c 98.7KB 0.000u 0:00.000

The resulting new JPG output files have today’s timestamp,
not that of the original GIF, So! ::

$for i in *.gif; do touch -r "$i" "${i%.*}.jpg"; done

This ‘touches’; (Sets the Timestamp) as the SAME as a Reference file– the Original.
Now Let’s mess with the file “witch.gif” for Testing; Then apply to All..

$jhead -exifmap witch.jpg
File name : witch.jpg
File size : 67559 bytes
File date : 2000:02:16 08:35:32
Resolution : 398 x 300
JPEG Quality : 92

No EXIF data Present. Let’s create it with the current File Date:
$jhead -mkexif witch.jpg
Modified: witch.jpg

Now Look: Additional MAP file EXIF records the EXIF
Timestamp as if when Picture was Taken
regardless of what happens to the file’s timestamp from here on out:

$jhead -exifmap witch.jpg
Map: 00008-00038: Directory
Map: 00038-00058: Data for tag 0132
Map: 00058-00076: Directory
Map: 00076-00096: Data for tag 9003
Map: 00096-00126: Directory
Map: 00126-00126: Thumbnail
Map: 00126- End of exif
Map: 00000 49 49 2a 00 08 00 00 00 02 00
.. thumbnail data, I think?? ...
Map: 00120 00 00 00 00 00 00 00 00 11 04
File name : witch.jpg
File size : 67677 bytes
File date : 2000:02:16 08:35:32
Date/Time : 2000:02:16 08:35:32
Resolution : 398 x 300
JPEG Quality : 92
______________________

Use the Manual Pages for these Utilities here for much more useful stuff : )

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.