ExifTool Forum

ExifTool => Newbies => Topic started by: Hugh on February 08, 2016, 11:11:56 AM

Title: Copying directory structure
Post by: Hugh on February 08, 2016, 11:11:56 AM
I have found that the command
exiftool -k -r -sep "; " "-Subject<XPKeywords" "C:\My Progs\ExifTool\Before" -o "C:\My Progs\ExifTool\After"
will recurse through and process all the files in subdirectories of the Before directory, but all the new files are put in After.

Is it possible to specify that the directory structure under Before is replicated under After?
Title: Re: Copying directory structure
Post by: Phil Harvey on February 08, 2016, 11:18:16 AM
Here is one way to do this:

1. cd C:

2. cd "\My Progs\ExifTool\Before"

3. exiftool -k -r -sep "; " "-Subject<XPKeywords" . -o "C:\My Progs\ExifTool\After\%d\"

- Phil
Title: Re: Copying directory structure
Post by: Hugh on February 08, 2016, 11:29:23 AM
Thanks.
Title: Re: Copying directory structure
Post by: Hugh on February 08, 2016, 12:12:26 PM
I'm afraid I'm having trouble making this work from a Windows batch file. I've changed %d to %%d, so my batch file now reads:
cd C:
cd "\My Progs\ExifTool\Before"
"C:\My Progs\ExifTool\exiftool.exe" -k -r -sep "; " "-Subject<XPKeywords" . -o "C:\My Progs\ExifTool\After\%%d\"


However, ExifTool reports an error for every file:
Error: Error creating file: C:/My Progs/ExifTool/After/./Subfolder/IMG_5669.JPG - ./Subfolder/IMG_5669.JPG

There seems to be an extraneous dot in the output path.
Title: Re: Copying directory structure
Post by: Phil Harvey on February 08, 2016, 12:37:20 PM
I wouldn't thikn that the extra "." should matter (at least it doesn't on Mac/Linux systems), but you may be able to get rid of it like this:

cd c:
cd "\My Progs\ExifTool\Before"
"C:\My Progs\ExifTool\exiftool.exe" -k -r -sep "; " "-Subject<XPKeywords" * -o "C:\My Progs\ExifTool\After\%%d\"

I think this should work if the directory names in the Before directory don't have extensions.  However, it probably only work for files in subdirectories, and not in the main Before directory.

Alternatively, the failure could be caused by a permission problem.

- Phil

Edit: Another option would be to use the advanced features of %d to remove the root directories from this string.  See the -w option documentation for details
Title: Re: Copying directory structure
Post by: Hugh on February 08, 2016, 01:11:20 PM
Thank you for your patience.

I'm afraid I don't know how to copy and paste ExifTool's error messages and I missed out /" from the output path when transcribing the error message. I'm sorry.

With my previous code, the error message was:
Error: Error creating file: C:/My Progs/ExifTool/After/./Subfolder/"/IMG_5669.JPG - ./Subfolder/IMG_5669.JPG

Replacing the dot before -o in the command with an asterisk results in the following error message:
Error: Error creating file: C:/My Progs/ExifTool/After/Subfolder/"/IMG_5669.JPG - ./Subfolder/IMG_5669.JPG
The dot has gone from the output path but the extraneous  /" or "/ is still there between directory name and filename.

The batch file (copied and pasted from my text editor) is exactly as follows:
cd C:
cd "\My Progs\ExifTool\Before"
"C:\My Progs\ExifTool\exiftool.exe" -k -r -sep "; " "-LastKeywordXMP<XPKeywords" "-Subject<XPKeywords" "-xmp:Rating<Rating" * -o "C:\My Progs\ExifTool\After\%%d\"
Title: Re: Copying directory structure
Post by: Phil Harvey on February 08, 2016, 01:15:27 PM
OK.  This appears to be a problem with escaping the quote.  Try using forward slashes instead of backward slashes.

I don't know all the ins and outs of escaping on the Windows command line, but this should solve the problem if the backslash is used for escaping.

- Phil
Title: Re: Copying directory structure
Post by: Hugh on February 08, 2016, 02:42:26 PM
Excellent. That seems to have done the trick.

My batch file now reads:
cd C:
cd "\My Progs\ExifTool\Before"
"C:\My Progs\ExifTool\exiftool.exe" -k -r -sep "; " "-LastKeywordXMP<XPKeywords" "-Subject<XPKeywords" "-xmp:Rating<Rating" * -o "C:/My Progs/ExifTool/After/%%d/"


Thank you very much.