Adding metadata to files beginning with...

Started by sjw, November 13, 2020, 06:00:50 AM

Previous topic - Next topic

sjw

Hi, first post, so bit of a noob one I guess.  First off, awesome app - many, many thanks.  While I've spent hours on it, it's certainly saved me many, many more.  So much so I've donated to help with your costs - first time I've ever felt the 'need' to do so to be honest.
Anyway, I'm sure this is a quick one...
I've used a few different commands to help get my photos in some semblance of order and they work so well.
I've used a command:
exiftool "-datetimeoriginal<${filename;$_=substr($_,0,12)} 00:00" "-filecreatedate<${filename;$_=substr($_,0,12)} 00:00" "-filemodifydate<${filename;$_=substr($_,0,12)} 00:00" "-alldates<${filename;$_=substr($_,0,12)} 00:00" -P -overwrite_original
to help me add/change dates to some WhatsApp files I had (based on their name).  I also have a folder with some WhatsApp files and 'others' too.  What do I need to add to the above command to just deal with files beginning with IMG?  I don't know if it's a 'find' or if IMG* can just slot in somewhere near each 'filename' instance.

Is there away of dragging files into a cmd prompt (so I could just deal with selected items within a folder)?  Some sort of icon/bat file with commands in that I could drop files in would be amazing instead of me typing them in each time.

I'm using Windows 10.

Many thanks!

Phil Harvey

On the command line, you could specify "IMG*" for the file name to select only files starting with IMG.  But for drag and drop or processing subdirectories, this won't work.  For this, you could add -if4 "$filename =~ /^IMG/" to the command.

To drag and drop on a .bat file, put your command in the .bat file and use %* for the file name.  This will expand to whatever files you drag and drop on it.

- 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 ($).

sjw

#2
Thanks for the reply Phil.
Not quite sure how to put it into practice though as I'm not sure which part completely represents the filename.
If I want to edit files beginning with IMG and limited to the first 12 characters to use, what would the command be?
If I want to edit any files beginning with IMG what would the command be?
For the if statement, would that just go into the command anywhere?

Aah, Doh!  You mean IMG* at the end.  :-[

Thanks!

StarGeek

Quote from: sjw on November 13, 2020, 10:40:48 AM
If I want to edit files beginning with IMG and limited to the first 12 characters to use, what would the command be?
If I want to edit any files beginning with IMG what would the command be?
I'm not sure if I understand this.  The check for IMG is separate than using the first 12 characters.  The first is in the -if option and the second is part of the tag copy procedure that you already have listed.

QuoteFor the if statement, would that just go into the command anywhere?
Pretty much.  It just can't split up an option that requires a second argument.  Your listed command doesn't have any of those, so you could put it anywhere.

QuoteAah, Doh!  You mean IMG* at the end.
No, not if you're talking about putting the command in a bat file.  The %* in a bat file stands for the the arguments that are passed to the bat file.  In the case of dragging/dropping files on to the bat file, it would be a list of all the files that get dropped onto it.  For example, if you had this in a bat file
exiftool -DateTimeOriginal %*
then dragging/dropping files onto the bat file will give the DateTimeOriginal of all those files.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sjw

Sorry, my 'Doh' was an edit refering to the questions above, I added the %* to the bat file OK.
For example:
c:\users\ste\desktop\exiftool "-datetimeoriginal<${filename;$_=substr($_,0,12)} 00:00" "-filecreatedate<${filename;$_=substr($_,0,12)} 00:00" "-filemodifydate<${filename;$_=substr($_,0,12)} 00:00" "-alldates<${filename;$_=substr($_,0,12)} 00:00" -P -overwrite_original %* in a .bat file would change the Date Taken and file created & modified according to the names of the files dragged into it yes?

For the other points though:
I want both arguments to be taken into account.
i.e. what is the command to make the changes to files in a folder that begin with IMG (because there could be files that begin with ABC that also have a date format in that I want to ignore)?
exiftool "-datetimeoriginal<${filename;$_=substr($_,0,12)} 00:00" "-filecreatedate<${filename;$_=substr($_,0,12)} 00:00" "-filemodifydate<${filename;$_=substr($_,0,12)} 00:00" "-alldates<${filename;$_=substr($_,0,12)} 00:00" -P -overwrite_original DIR/IMG* ?
Or:
exiftool "-datetimeoriginal<${filename;$_=substr($_,0,12)} 00:00" "-filecreatedate<${filename;$_=substr($_,0,12)} 00:00" "-filemodifydate<${filename;$_=substr($_,0,12)} 00:00" "-alldates<${filename;$_=substr($_,0,12)} 00:00" -P -overwrite_original -if4 "$filename =~ /^IMG/" DIR

StarGeek

Both those command do the same thing, work only on files that start with IMG.  I don't know your date format so I can't comment on how to add that in.

Also, you can drop "-datetimeoriginal<${filename;$_=substr($_,0,12)} 00:00"DateTimeOriginal is part of the AllDates shortcut and will be written with that part of the command.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sjw

Thanks StarGeek - just wanted the clarification that DIR/IMG* was a valid option.
Other option dropped too - cheers!

StarGeek

DIR/IMG* is a valid option, but it doesn't work if you want to recurse with the -r (-recurse) option.  See the docs in that link and Common Mistake #2 for details.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).