Keeping part of dir name in a renamed dir

Started by teroka, September 12, 2021, 09:07:11 PM

Previous topic - Next topic

teroka

Dear Phil,

Thank you very much for sharing this great app with all of us!

Although I realize this is quite a powerful tool, I am not sure how to do what I need in this particular case, and I'd appreciate if you could help me out with the following situation:


I have many images copied to separate directories like this:

(taken on 2021.05.11, but copied on 2021.05.14)
2021.05.14 Short description 1/
  img_1.jpg 
  img_2.jpg 
  img_3.jpg 


(taken on 2021.07.12, but copied on 2021.07.18)
2021.07.18 Short description 2/
  img_1.jpg 
  img_5.jpg 
  img_7.jpg 




I would like to have those moved to a dir structure, based on their real creation date,
and to also keep the "Short description" parts in the destination directory names,
like this:

2021/2021.05/2021.05.11 Short description 1/
   img_1.jpg
   img_2.jpg
   img_3.jpg


2021/2021.07/2021.07.12 Short description 2/
   img_1.jpg
   img_5.jpg
   img_7.jpg



Is that possible and could you please share a command line that would do that transformation?

Thanks!

StarGeek

This command assumes that the Year/Year.Month/ part of the directory doesn't change and that the timestamp used is DateTimeOriginal.  Also, you can't run it from the same directory as the files, you have to be at least 1 level  up.  For example, you can't CD into 2021/2021.07/2021.07.18/ and run it from there.  You would have to be no deeper than 2021/2021.07/ and use 2021.07.18/ as the path.  Though a complete path would be best

Try this.  If the results look good, then change TestName to FileName
exiftool -d "%Y.%m.%d" "-Testname<%-:1d/$DateTimeOriginal ${Directory;m/\d{4}\.\d\d\.\d\d\s+([^\/]+$)/;$_=$1}/%F" /path/to/files/

Example output
C:\>exiftool -d "%Y.%m.%d" "-Testname<%-:1d/$DateTimeOriginal ${Directory;m/\d{4}\.\d\d\.\d\d\s+([^\/]+$)/;$_=$1}/%F" "Y:\!temp\2021\2021.05\2021.05.17 Short description 1\Test4.jpg"
'Y:/!temp/2021/2021.05/2021.05.17 Short description 1/Test4.jpg' --> 'Y:/!temp/2021/2021.05/2021.05.11 Short description 1/Test4.jpg'
    0 image files updated
    1 image files unchanged


If the Year or Year.Month part of the path might change, then that would require adjustments to the command.
"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

teroka

Thanks, StarGeek! Works as you described...

By the way, what exactly is the idea behind the "%-:1d" (in: "-Testname<%-:1d/$DateTimeOriginal ${Directory;m/\d{4}\.\d\d\.\d\d\s+([^\/]+$)/;$_=$1}/%F")

StarGeek

Details can be found under the "Advanced features" section of the -w (-TextOut) option.

In this case, you start with %d, which represents the directory of the file being processed.  The -:1 part does some editing on the directory path.  The minus sign says to remove data from the end, the colon means remove full directory names (as opposed to a dot which would remove individual characters), and the 1 indicates only one level is to be removed.  So the end result, given the example path of 2021/2021.05/2021.05.14 Short description 1/, it would remove the 2021.05.14 Short description 1 part of the path, which is then recreated using the correct data in the rest of the command.

This part is there just in case one of the files is currently in a directory that is a different month than indicated by the embedded data.
"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

Phil Harvey

StarGeek is really a wizard with these tricky ExifTool commands.

Plus, his explanations really detailed and helpful.

:)
...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

Some people do sudoku or crossword puzzles.  Exiftool commands fulfill the same niche for me. :D
"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

Phil Harvey

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