ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: sevy on June 04, 2019, 10:44:28 AM

Title: rename file (with delete of characters)
Post by: sevy on June 04, 2019, 10:44:28 AM
Hello,

I recently learn thanks to this forum how to rename pictures without GPS coordinates.
Then, I may manually add a location, so files named with "_NOGPS" have coordinates.
I know how to find those files 
exiftool -if "$filename=~/NOGPS/" -if "not $gpslatitude" -sourcefile .

but how to rename them? as they have now gps coordinates, P1234567_NOGPS.JPG should be P1234567.JPG

is it possible to perform this operation with exiftool ?

thanks in advance
Title: Re: rename file (with delete of characters)
Post by: Phil Harvey on June 04, 2019, 10:48:03 AM
Maybe something like this?:

exiftool -if "$filename=~/NOGPS/ and $gpslatitude" "-testname<${filename;s/_NOGPS//}" DIR

If this does what you want, then replace "testname" with "filename" to actually do the renaming.

- Phil
Title: Re: rename file (with delete of characters)
Post by: sevy on June 04, 2019, 11:49:18 AM
Wonderful , according my first test, it is doing what I want ! Thanks a lot !

I do not well understand the syntax : ;s/_NOGPS//
;s for suppress ?
/_NOGPS/ is the string to be deleted
but what about the last / ?

once again, thanks for the help !
Title: Re: rename file (with delete of characters)
Post by: StarGeek on June 04, 2019, 12:02:33 PM
s/_NOGPS// is a Regular Expression (RegEx) substitution.  The s is for substitution, there is also m for a simple match.  The characters between the first two slashes is the pattern that is being searched for, in this case _NOGPS.  The pattern between the second two slashes is what will be substituted, in this case, nothing.  It is basically s/SearchTerm/Replacement/.

RegEx is very complicated and very powerful.  Teaching all the details really is beyond the scope of this forum.  There are a lot of websites out there that can teach you about it if you're interested, such as Regular-Expressions.info (https://www.regular-expressions.info/), which is the site I learned from.  But as long as you keep to simple alphanumeric characters (a-z, 0-9), you can easily do removal and replacements with exiftool.  But other symbols, such as the dot . or asterisk * have different meanings.
Title: Re: rename file (with delete of characters)
Post by: sevy on June 04, 2019, 12:56:07 PM
thanks, i will try to learn RegEx.