Removing Multiple Number attribute to change the date of the file.

Started by jhz77777, January 17, 2024, 10:33:01 AM

Previous topic - Next topic

jhz77777

I have a folder with a very annoying naming convection.  I am trying to change the date of of the file using the file name and can not figure out how to use the numbers past the 3rd "-".  Here is an example file name.  "860322062221178-60-4-12092023231954-W1000099.JPG".  They all have "860322062221178-X-X-" in front.  The X-X are variable in length between 2 and 3 numbers.  I tried
exiftool "-createdate<${filename;s/^[^-]*//} 00"
and that didn't work Any suggestions?

StarGeek

What is the date in that file name?  I can see a 2023, but that's followed by 23, which obviously can't be the month.
* 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).

jhz77777

It is date/time in 24hour formate.   12092023231954.  12/09/2023 23:19:54. 


StarGeek

The "-createdate<Filename" will only work if the time stamp is in largest (Year) to smallest (seconds) format.  So that will need to be rearranged.

This command will do so as long as the date/time is followed by "-w"
exiftool "-CreateDate<${Filename;m/(\d\d)(\d\d)(\d{4})(\d{6})-w/i;$_=$3.$2.$1.$4}" /path/to/files/

If the letter can be variable, then this will need some changes.
* 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).

jhz77777

Thank you.  I do have some files with an H instead of a W.   They will be the only two letters.  Is there a way to incorporate that?

jhz77777

#5
I removed the different files and tried to run it on just one and I am getting a "bad substitution" error. 

(base)  ~ % exiftool "-CreateDate<${Filename;m/(\d\d)(\d\d)(\d{4})(\d{6})-w/i;$_=$3.$2.$1.$4}" /Users/me/Documents/BladeCam/Lens1/reveal-images4
zsh: bad substitution

jhz77777

#6
I changed the "" to ' and still no luck. 

exiftool '-createDate<${filename;m/(\d\d)(\d\d)(\d{4})(\d{6})-w/i;$_=$3.$2.$1.$4}' /Users/me/Documents/BladeCam/Lens1/reveal-images4/
zsh: bad substitution

StarGeek

Quote from: jhz77777 on January 17, 2024, 11:24:07 AMThank you.  I do have some files with an H instead of a W.   They will be the only two letters.  Is there a way to incorporate that?

Change -w to -[a-zA-Z].  That will match any letter from A-Z.
* 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).

StarGeek

Quote from: jhz77777 on January 17, 2024, 11:59:22 AMI changed the "" to ' and still no luck. 

exiftool '-createDate<${filename;m/(\d\d)(\d\d)(\d{4})(\d{6})-w/i;$_=$3.$2.$1.$4}' /Users/me/Documents/BladeCam/Lens1/reveal-images4/
zsh: bad substitution

This should work.  You need single quotes around anything with a dollar sign on Mac/Linux. That's the limit of my ability, as I don't have access to Linux/Mac. Hopefully someone here with will be able to help.
* 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).

Phil Harvey

I run your command in zsh and I don't get the same problem.  This is a zsh error message, so there must be something wrong with the syntax of your command, but when I cut and paste it here I don't see the problem.  Try working up from a simpler command to find out where it breaks.

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

StarGeek

Also, don't cut/paste from a word processor or Google Docs.  Those will "help" you by changing regular quotes into smart quotes.
* 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).

jhz77777

#11
It was a copy and paste error.  I did make one edit in case anyone reads this later.  The month and day were swapped but I think I fixed it which would have impossible without your help. 

exiftool '-createDate<${filename;m/(\d\d)(\d\d)(\d{4})(\d{6})-w/i;$_=$3.$1.$2.$4}' /Users/me/Documents/BladeCam/Lens1/reveal-images4