Author Topic: Renaming files by XPKeywords  (Read 4178 times)

BrentT

  • Jr. Member
  • **
  • Posts: 10
Renaming files by XPKeywords
« on: July 07, 2011, 03:58:30 PM »
I have my wildlife images organized by taxonomy.  I tag each file in Windows Photo Live Gallery and it is stored under XPKeywords.

An example of a tag is 2_Bugs/Dragonflies/Dragonflies/5_Emeralds/2_Somatoclora/06_DelicateEmerald

I wanted to rename all the files in a directory based on the tag XPKeywords so that the images remain in proper taxonomy order when I copy image files onto an extra SD card that I can slide into my television.  Currently the images are alphabetically ordered by their original filename on the camera when viewed on the TV.
 
I tried:
exiftool "-FileName<-XPKeywords" g:\100_366.jpg
as an example and the file was not renamed.  I am not sure also if exiftool will accept g:\*.* as syntax for all the files in a directory.

What am I missing here?  Is it an error with the syntax or with the '/' in the tags? 

I can see that the renaming will create subdirectories many levels deep.  Can the '/' characters be changed to something else if the SD card software on the television doesn't handle nested subdirectories very well?

Thanks, Brent

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16879
    • ExifTool Home Page
Re: Renaming files by XPKeywords
« Reply #1 on: July 07, 2011, 07:29:44 PM »
Hi Brent,

Your main problem is that you put a dash before XPKeywords.  You should have done this:

exiftool "-filename<xpkeywords" g:\*.*

But there are 2 more problems:

1) Your files will lose their extension.  To solve this, add "%e":

exiftool "-filename<xpkeywords.%e" g:\*.*

2) If the XPKeywords contain a slash or backslash, this will be interpreted as a directory separator.  So this command:

exiftool "-FileName<-XPKeywords" g:\100_366.jpg

will move and rename the file to

g:\2_Bugs\Dragonflies\Dragonflies\5_Emeralds\2_Somatoclora\06_DelicateEmerald.jpg

assuming that same XPKeywords as in your example.

You would have to get into creating a user-defined tag if you wanted to change the format of XPKeywords to substitute the slashes.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BrentT

  • Jr. Member
  • **
  • Posts: 10
Re: Renaming files by XPKeywords
« Reply #2 on: July 07, 2011, 11:12:44 PM »
Thanks, I am getting somewhere.  It works as long as you run the exiftool command from the directory where the files are you want to change.

But two problems remain.

exiftool -"filename<xpkeywords" g:\*.*

Almost works.  But the extension .jpg is missing as you said.

exiftool "-filename<xpkeywords.%e" g:\100_0371.jpg

Does not work.  I think exiftool is thinking that I am trying to extract the tag "XPkeywords.%e" from the file to give to the -filename argument.  It is giving the error message "No writable tags found"

I have tried

exiftool "-filename<xpkeywords$.%e" g:\100_0371.jpg

but it reinterprets xpkeywords as a string and it renames the example file to:
xpkeywords$.jpg

The other problem is if I use the exact same tag in two different image files, it will not write the second or subsequent files because the filename has already been used. 

Two ways to handle this problem.  First is to append _1, _2 etc to the filename.  I don't think exiftool can do this currently.  The second option is to append the date and time to the image filename. 

But in order to do this it must be possible to concatenate two different types of information and pipe it to the filename command.  Can exiftool do this?

If not, I can always take the best image of species to show off to others.

As for replacing the "/" I could make a program to format the string different.  I would likely have to feed the string from xpkeywords to the program, get the program to put the output in a file that can be imported by exiftool.  I may have to find a copy of 4DOS or something else that has a command to process all the files in a directory from a command line.  I will try to figure this last part of the puzzle on my own.

Thanks for your help.  It is wonderful to have an author of a piece of software to provide so much help on a forum.

BrentT

  • Jr. Member
  • **
  • Posts: 10
Re: Renaming files by XPKeywords
« Reply #3 on: July 07, 2011, 11:21:06 PM »
Aaargh.  And I discovered another potential problem.  If I have two different tags because there are two different animals in a picture I would have to deal with a comma separating the tags and ideally write the file to the two different locations specified.  Or just jetison the second tag perhaps with the ignore errors command in exiftool.


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16879
    • ExifTool Home Page
Re: Renaming files by XPKeywords
« Reply #4 on: July 08, 2011, 07:33:12 AM »
t works as long as you run the exiftool command from the directory where the files are you want to change.

You can specify the output directory when you write the filename so you can run the command from anywhere.

Quote
exiftool "-filename<xpkeywords.%e" g:\100_0371.jpg

Does not work.  I think exiftool is thinking that I am trying to extract the tag "XPkeywords.%e" from the file to give to the -filename argument.  It is giving the error message "No writable tags found"

Oops.. Sorry, my mistake.  Try this:

exiftool "-filename<g:\$xpkeywords.%e" g:\100_0371.jpg

Here I specified the output directory too.

Quote
The other problem is if I use the exact same tag in two different image files, it will not write the second or subsequent files because the filename has already been used. 

Two ways to handle this problem.  First is to append _1, _2 etc to the filename.  I don't think exiftool can do this currently.

Yes it can, using the %c formatting code:

exiftool "-filename<g:\$xpkeywords%+c.%e" DIR

Quote
The second option is to append the date and time to the image filename.

exiftool "-filename<g:\${xpkeywords}_$datetimeoriginal.%e" -d %Y%m%d%H%M%S DIR

Note that I had to put braces around "xpkeywords" here because otherwise the following underline would be taken as part of the tag name.  Valid characters in a tag name are - _ A-Z a-z 0-9.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

BrentT

  • Jr. Member
  • **
  • Posts: 10
Re: Renaming files by XPKeywords
« Reply #5 on: July 10, 2011, 08:40:36 PM »
I've got it to work, thanks.

Cheers, Brent

BrentT

  • Jr. Member
  • **
  • Posts: 10
Re: Renaming files by XPKeywords
« Reply #6 on: July 10, 2011, 09:06:07 PM »
A little suggestion.  In your command reference for Exiftool you can document the meaning of all the special characters and the context they are used in.  This could reduce some of the support you need to do in the forums.

I am referring to
- The standard command prefix
' (Linux) or " (Windows) Quotes for handling strings
$ The command prefix for use inside quotations instead of -
{} Brackets to tell when the name of a command is at an end to prevent confusion inside quotations for the rest of the contents of the quotations
% A sub command prefix
< Piping
#
=
:
etc

Cheers, Brent

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16879
    • ExifTool Home Page
Re: Renaming files by XPKeywords
« Reply #7 on: July 11, 2011, 08:45:27 AM »
Hi Brent,

A little suggestion.  In your command reference for Exiftool you can document the meaning of all the special characters and the context they are used in.  This could reduce some of the support you need to do in the forums.

This is a reasonable suggestion, but try to avoid getting into the details of specific shells unless absolutely necessary, for a few reasons:

1) I am not an expert on all shells

2) I don't know the full set of special characters for all shells

3) There are so many different shells: cmd, PowerShell, sh, csh, tcsh, bash, zsh, ...

So my hope is that people will know their own shells, although it looks like this talent is becoming less and less common.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).