ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: brettlid on September 01, 2011, 04:21:21 PM

Title: conditional -tagsfromfile?
Post by: brettlid on September 01, 2011, 04:21:21 PM
Hi,

I'm trying to conditionally rename *.m2ts files along with some sidecar files *.modd used by Sony PMB. I'm able to get two lines working from the command line the first renaming the sidecar file and then renaming the *.m2ts file based on the -DateTimeOriginal tag.

The below lines work fine, but rename all the files in the directory.

exiftool.exe  -tagsfromfile %f *.modd  "-FileName<${DateTimeOriginal}.m2ts.%e" -d "%Y-%m-%d %H%M-%S" 
exiftool.exe  "-FileName<${DateTimeOriginal}.%e" -d "%Y-%m-%d %H%M-%S"  *.m2ts


Now if try to prossess the files based on the condition of a tag, i.e.   -Make = "Sony". The second line works fine, renaming the *.m2ts files based on the condition. The first line fails as it tries to read the *.modd file for the -Make tag instead of the *.m2ts file as i would like it to.


exiftool.exe  -if "<Make eq 'Sony'" -tagsfromfile %f *.modd  "-FileName<${DateTimeOriginal}.m2ts.%e" -d "%Y-%m-%d %H%M-%S" 
exiftool.exe  -if "<Make eq 'Sony'" "-FileName<${DateTimeOriginal}.%e" -d "%Y-%m-%d %H%M-%S"  *.m2ts


Hope i explained it right. If you can give me any help on how to accomplish this it would be greatly appreciated.

Thanks, Brett
Title: Re: conditional -tagsfromfile?
Post by: Phil Harvey on September 02, 2011, 07:23:25 AM
Hi Brett,

exiftool.exe  -tagsfromfile %f *.modd  "-FileName<${DateTimeOriginal}.m2ts.%e" -d "%Y-%m-%d %H%M-%S" 
exiftool.exe  "-FileName<${DateTimeOriginal}.%e" -d "%Y-%m-%d %H%M-%S"  *.m2ts


Your first command looks funny.   -tagsfromfile %f will take the tags from a file with no extension.

Your problem with the -if condition is a real problem because the condition always operates on the file being processed.  The only solution I can think of is to write a simple script to do this task for you.  You can loop through all M2TS files in a directory, testing with the -if condition to get only the Sony files, then rename the MODD and M2TS files if the condition is satisfied.  The application will return 1 if the condition failed, and 0 otherwise.

I could maybe help you write the script if you think this is an option.  If so, I need to know what type of shell you are using?  I'd guess the Windows cmd shell based on your commands.

- Phil
Title: Re: conditional -tagsfromfile?
Post by: brettlid on September 02, 2011, 11:54:22 AM
Hi Phil

Yes i was afraid that was the issue. I'm using a windows command shell, but not very familiar with loop thru all the files in the directory. Any help you can give me would be greatly appreciated.

Thanks, Brett

PS the first command works as the MODD file names are named as such "movie.m2ts.modd"
Title: Re: conditional -tagsfromfile?
Post by: Phil Harvey on September 02, 2011, 09:07:12 PM
OK.  I'm not familiar with Windows .bat files either, but I'll do some googling tomorrow and see what I can come up with.

- Phil
Title: Re: conditional -tagsfromfile?
Post by: Phil Harvey on September 03, 2011, 08:34:48 AM
OK.  Here is a batch file that should do what you want:

@echo off
if %1.==_Sub. goto Sub

for %%a in (%*) do call %0 _Sub "%%a"
goto End

:Sub
exiftool -if "$make eq 'SONY'" -filename %2 > NUL
if ERRORLEVEL==1 goto Fail
echo Pass: %2
exiftool -tagsfromfile %%d%%f "-filename<${datetimeoriginal}.m2ts.%%e" -d "%%Y-%%m-%%d %%H%%M-%%S" %2.modd
exiftool "-filename<${datetimeoriginal}.%%e" -d "%%Y-%%m-%%d %%H%%M-%%S" %2
goto End

:Fail
echo Fail: %2

:End


You use it like this:  BATCH *.m2ts

And it should rename only the .m2ts and .m2ts.modd files with a Make of SONY.

I had to use a sneaky trick of calling the batch file again from inside the for loop because apparently you can't use a goto inside a for loop.  Windows batch files seem to be somewhat crippled compared to other scripting languages.

- Phil