rename file (with delete of characters)

Started by sevy, June 04, 2019, 10:44:28 AM

Previous topic - Next topic

sevy

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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

sevy

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 !

StarGeek

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, 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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

sevy