Exiftool 9.76 - Windows 7 64bit
I've been attempting to create concatenated file names from the existing full directory & existing file names.
The following simple command does almost exactly what I want
exiftool -p -o -r "-filename < ${directory;} %%f.%%e" %1
- but doesn't separate the directory folder structure as I require.
However, when I try to substitute '#' characters for the Windows '\' (as separators)
exiftool -p -o -r "-filename < ${directory;(\)(#)} %%f.%%e" %1
I get an error message:-
Warning: syntax error for directory - EXTENDED DIRECTORY (= existing directory structure + filename)
and the image files in the deepest folder are moved down one level
If I substitute a forward slash / for the Windows \ It gives
Warning: Search pattern not terminated - which is predictable I guess.
Have read all other similar forum posts & spent far too long on this - missing something obvious probably.
Any assistance would be very much appreciated.
Paul
Can you provide an example (before and after full filenames) of what you are trying to achieve exactly? I'm sure we can then get it to work :)
C:\
Folder1\
Folder2\
imagex.jpg
imagey.jpg
Folder3\
imagez.jpg
becomes
#C:#Folder1#Folder2#imagex.jpg#
#C:#Folder1#Folder2#imagey.jpg#
#C:#Folder3#imagez#
(the leading & trailing '#' are not essential)
thanks for your offer to assist
Quote from: Shackers on November 22, 2014, 02:28:25 PM
#C:#Folder1#Folder2#imagex.jpg#
#C:#Folder1#Folder2#imagey.jpg#
#C:#Folder3#imagez#
For one thing, the colon is a reserved characters in windows, so you're going to have to remove or change that as well.
Quoteexiftool -p -o -r "-filename < ${directory;(\)(#)} %%f.%%e" %1
My perl is not the best but I think you have a couple mistakes here. First, I think you need the
s to actually do substitution. At least, I couldn't find any examples that didn't have it. Second, you're going to need the
g option for it to substitute all the matches. Finally, I think that Exiftool uses forward slashes in the directory name.
So maybe try something like this? I haven't extensively tested this, so be careful. (I had to switch from s()() to s/// on the second part to get rid of a forum smiley)
exiftool -p -o -r "-filename < ${directory;s(/)(#)g;s/://} %%f.%%e" %1Oh yeah, I think the
-o needs a directory or filename specified for it. It's not an option I've used, so I'm not to familiar with it.
OK - with a very minor modification (to add a '#' between the deepest folder and the file name) - that works perfectly.
exiftool -p -o -r "-filename < ${directory;s(/)(#)g;s/://}#%%f.%%e" %1
Puzzled as to why forward slashes are required in the substitution since Windows uses backslashes. Also not sure as to when to use the ()() or the /// form of the substitution method.
I'm also unclear about the -o option syntax - tried appending /dummy but that triggered an error message so I'm quitting while I'm ahead.
I really appreciate the fact that you've taken the time to help me out.
Thank you
Quote from: Shackers on November 22, 2014, 05:13:19 PM
Also not sure as to when to use the ()() or the /// form of the substitution method.
Either is fine, they are the same for the most part. One place where it's easier to use the ()() is when you have slashes in your substitution. Using the /// form when you have a / in the substitution means you would have to escape it. For example, if you want to change double slashes to single slashes, it would look like this /\/\//\//, which is messy and hard to understand. With the parens it would be (//)(/).
In perl, you can choose what delimiter to use (you specify it after the s in this case). The standard is the forward slash, but you can use braces, or any other character. I frequently use the # as that symbol is rarely used by me in the pattern.
If you want to learn more about perl regular expressions, have a look at the perlre documentation. Run perldoc perlre on the command-line or browse to http://perldoc.perl.org/perlre.html (http://perldoc.perl.org/perlre.html) (Note: the web version describes the latest release of perl, 5.20.1 at this moment, and may describe features that are not yet in your particular version of perl. The differences aren't too big though so if perldoc doesn't work for you, the web is the place to go).
Thanks Hayo - I'll do that - and thanks again for your help. Also to StarGeek - what a great name!
Quote from: StarGeek on November 22, 2014, 05:26:17 PM
it would look like this /\/\//\//
This is known as leaning toothpick syndrome. :)
- Phil
Quote from: Phil Harvey on November 24, 2014, 07:11:43 AM
Quote from: StarGeek on November 22, 2014, 05:26:17 PM
it would look like this /\/\//\//
This is known as leaning toothpick syndrome. :)
That's it. I couldn't remember at the time and was in a rush so I couldn't look it up.
Is it weird that I have a script that will take what I have in the clipboard and escape it like this for when I do searches with ExifTool? :)
Absolutely not weird at all - not even slightly weird. :)
I am worried by the fact that Shackers doesn't think this is weird. ;)
The following Windows Exiftool command fails when there's a minor error in a header.
:: s(/)(#) substitutes '/' with '#' in directory structure
:: s(:)(//) removes ':'
:: #%%f.%%e prefixes filename with '#' and appends existing filetype
exiftool -r -m "-filename < ${directory;s(/)(#)g;s/://}#%%f.%%e" %1
As you can see from the attached 'capture1' image, the above command works fine on the 5x .JPG files but fails on the 5x .MPG
'capture2' displays the header for one of the .MPG files
Given that I've specified a -m tag, why does a (lowercase) minor error cause the command to ignore the image file causing it?
Is this a case of Exiftool being very careful & if so, how can I convince it to be more daring?
I'll try the -F option.
Nope - that didn't work.
This is FAQ number 16 (https://exiftool.org/faq.html#Q16).
- Phil
Phil
Sorry I missed that one. I guess I skipped over it because the JPG files were being processed successfully & the command is essentially renaming files as opposed to writing them. The Makernote diagnostic message was the red herring I was blindly following.
I found that when I inserted -ext MPG into the command it processed that filetype but then ignored the JPGs.
In order to do both I needed to insert -ext JPG & -ext MPG. That was depressing since my application ranges across potentially ALL the different filetypes.
As an experiment I tried
exiftool -r -m -ext * "-filename < ${directory;s(/)(#)g;s/://}#%%f.%%e" %1
and it worked on both - and presumably? all others!
That's a relief because now I can continue using Exiftool for this part of the overall job even though I suppose it's not really the right tool for this function.
Thanks once again & I'll try to be more thorough in reading the FAQs in future
Hi Shackers,
Quote from: Shackers on March 12, 2015, 02:39:50 AM
As an experiment I tried
exiftool -r -m -ext * "-filename < ${directory;s(/)(#)g;s/://}#%%f.%%e" %1
and it worked on both - and presumably? all others!
Yes. Well done.
- Phil