Use Part of Foldername in Filename

Started by Daniel L S, March 08, 2016, 06:28:02 AM

Previous topic - Next topic

Daniel L S

I want part of FOLDERname in the FILEname.
I save photos in folder DATE PLACE like this:
\2015-09-21 Sicily Palermo\
\2015-11-01 Car show\


I want filename look like this: DATE TIME PLACE.JPG (PLACE from folder name).
With this: exiftool -m -V0 "-FileName<CreateDate" -d %%Y%%m%%d_%%H%%M_%%S%%%%-c.%%%%e -EXT JPG *
I get: 20150921_0807_27.JPG (YEARMONTHDAY_HOURMIN_SEC-COUNTER)
But want: 20150921_0807_27 - Sicily Palermo.JPG

I thankful if someone help me how to do this in batch script on Windows.




Phil Harvey

Try this:

exiftool -m -V0 "-FileName<${CreateDate} -${Directory;s(.*/)();s(\S+)()}%%-c.%%e" -d %%Y%%m%%d_%%H%%M_%%S -ext jpg .

I don't have time to test this right now, but I think it should work.  The subsitutions in the Directory tag isolate the last folder in the directory, then remove the first word (the date) from this name.

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

Daniel L S

IT WORKS!

Thank you very much! I really appreciates! VERY!



petkos01

#3
Sorry I am new here but I have a question.
I was glad to find this post because I need to use beginning of the folder name in filename. Files in folder [20061225 Italy] would be named "20061225 old_filename.jpg"

I wanted to use this example above as start point. I just need do remove part after space not before as in example. But just testing example above resulted in corrupted filenames. And post at the and says "It worked."

d:\test\2015-09-21 Sicily Palermo>"d:\Program Files Portable\Exiftool\exiftool.exe" -m -V0 "-FileName<${CreateDate} -${Directory;s(.*/)();s(\S+)()}%%-c.%%e" -d %%Y%%m%%d_%%H%%M_%%S -ext jpg .
======== ./55_02.jpg
======== ./55_03.jpg
======== ./55_04.jpg
    1 directories scanned
    3 image files updated

Result filenames.
  Directory of d:\test\2015-09-21 Sicily Palermo


2016-09-01  17:35    <DIR>          .
2016-09-01  17:35    <DIR>          ..
2016-08-22  14:57         7,304,766  -%-1.%jpg
2016-08-22  14:57         5,831,158  -%-2.%jpg
2016-08-22  14:57         7,034,728  -%.%jpg
               3 File(s)     20,170,652 bytes

I've tried it with Linux version and the result is the same. Is it because I am using new version of ExifTool?
I am puzzled a bit.


Thank You for help.


Hayo Baan

The double percent signs are your problem. In Windows batch files they need to be doubled, but not on the command line :)
Hayo Baan – Photography
Web: www.hayobaan.nl

petkos01

Thanks,I've tried that now. The same result without percentage signs.
There is issue with that {Directory regex substitution which should get "Sicily Palermo" from directory name and use as part of  filename. But it's too advanced for me.

StarGeek

Try passing the full path to the directory ("d:\test\2015-09-21 Sicily Palermo") (needs quotes since there is a space in it).  I believe that the Directory tag is only containing the dot.
* 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).

petkos01

Yes you are right. I've checked and directory tag is just dot. Is there any way to use actual directory in command example above for that substitution instead of tag Directory? I just want to rename files using part of directory name. I've found in documentation that actual directory is %%d. I've tried this:
exiftool -m -V0 "-FileName<${CreateDate} -${%%d;s(.*/)();s(\S+)()}%%-c.%%e" -d %%Y%%m%%d_%%H%%M_%%S -ext jpg .
but I was wrong.

Phil Harvey

Quote from: petkos01 on September 05, 2016, 09:40:50 AM
Is there any way to use actual directory in command example above for that substitution instead of tag Directory?

Sure, just specify the directory name on the command line instead of ".".

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

petkos01

Thank you. There are many folders and files. Could someone tell me how command would look like to do it all at once in my example? I've tried and I am doing something wrong.

Phil Harvey

instead of ".", put the names of all the directories you want to process. So the command would be:

exiftool -m -V0 "-FileName<${CreateDate} -${directory;s(.*/)();s(\S+)()}%%-c.%%e" -d %%Y%%m%%d_%%H%%M_%%S -ext jpg "directory name 1" "directory name 2"

You can have as many directory names as you want in the command.  Add -r to the command to also process sub-directories.  Usually if you use -r you can specify a single top-level directory.

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

petkos01

#11
Thank You for help and patience Phil. Now it's working.
It worked with directory names and when I swapped that for * it worked as well. It went through all directories and renamed all files.
exiftool -m -V0 "-FileName<${CreateDate} -${directory;s(.*/)();s(\S+)()}%%-c.%%e" -d %%Y%%m%%d_%%H%%M_%%S -ext jpg *
Or with dot but I needed to use -r argument
exiftool -m -V0 -r "-FileName<${CreateDate} -${directory;s(.*/)();s(\S+)()}%%-c.%%e" -d %%Y%%m%%d_%%H%%M_%%S -ext jpg .

kirk

#12
Hi, I wanted to piggy back off this thread.  I'm trying to change the DocumentName of tif files with a batch script to contain the folder name (that the batch file is in) and the filename separated by a "/".  The bat file is in a folder called "31822000473199" The tif files are in their own folder called "bitonals" and they are named 00000001.tif, 000000002.tif, etc.  So far I have this:

exiftool "-documentname<${Directory;s(.*/)();s(\S+)()}/${filename}" -overwrite_original .\bitonals\*.tif

So What I'd like to see is Document Name : 31822000473199/00000001.tif but what I'm getting is Document Name : /00000001.tif

Is there a way to solve this?  Thanks in advance!

StarGeek

First, if that's your command, I'm surprised it works.  You have -documentname< duplicated.  It should be more like:
"-documentname<${Directory;s(.*/)();s(\S+)()}/${filename}"

But exiftool has no way of knowing where the bat file is being run from and can't pull in that data.  The Directory tag holds the directory of the file being processed. You're going to have to look into batch file documentation. This StackOverflow answer should have some good starting info.

Or, if the Bat file is always going to be in 31822000473199, you could just hard code it
exiftool "-documentname<31822000473199/$filename" -ext tif -overwrite_original .\bitonals\
* 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).

kirk

My apologies that's an error on my part copying and pasting.  The folder name isn't always going to be the same so I didn't want to hard code it.  So let's forget about the batch file for now, I'll take a look at the StackOverflow post though (thanks for that!). 

Let's say the folder structure is the same 31822000473199\bitonals\00000001.tif, is there a string for the directory a level higher than where the file is located?