Author Topic: Copying directory structure  (Read 1752 times)

Hugh

  • Jr. Member
  • **
  • Posts: 20
Copying directory structure
« 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?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: Copying directory structure
« Reply #1 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
...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 ($).

Hugh

  • Jr. Member
  • **
  • Posts: 20
Re: Copying directory structure
« Reply #2 on: February 08, 2016, 11:29:23 AM »
Thanks.

Hugh

  • Jr. Member
  • **
  • Posts: 20
Re: Copying directory structure
« Reply #3 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:
Code: [Select]
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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: Copying directory structure
« Reply #4 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
...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 ($).

Hugh

  • Jr. Member
  • **
  • Posts: 20
Re: Copying directory structure
« Reply #5 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:
Code: [Select]
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:
Code: [Select]
Error: Error creating file: C:/My Progs/ExifTool/After/Subfolder/"/IMG_5669.JPG - ./Subfolder/IMG_5669.JPGThe 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\"

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: Copying directory structure
« Reply #6 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
...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 ($).

Hugh

  • Jr. Member
  • **
  • Posts: 20
Re: Copying directory structure
« Reply #7 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.