Sometimes I get "" Sometimes not

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zzyzxroad
Posts: 3
Joined: 01 Mar 2011 12:12

Sometimes I get "" Sometimes not

#1 Post by zzyzxroad » 01 Mar 2011 12:19

I am using a batch to encode videos for virtualdub. I have used this scrip before and it works no problem. I have tried the last several days to make the code work using other tasks, and today I just realized that the script makes quotations when I didnt ask for them.

here is a small part of the script:

rem Add to scheduler batch
echo if exist %1.part1.avs J:\DESHAKER\VirtualDub\deinterlace1.bat %1 > J:\DESHAKER\VirtualDub\Picker.bat

echo if exist %1.part2.avs J:\DESHAKER\%1.deshake.bat %1.avi >> J:\DESHAKER\VirtualDub\Picker.bat

echo if exist %1.part3.avs J:\DESHAKER\VirtualDub\deshakecut.bat %1.avi.avi >> J:\DESHAKER\VirtualDub\Picker.bat


An this is what I NOW get, what I never used to get:
if exist "J:\DESHAKER\5 second.MTS".part1.avs J:\DESHAKER\VirtualDub\deinterlace1.bat "J:\DESHAKER\5 second.MTS"
if exist "J:\DESHAKER\5 second.MTS".part2.avs J:\DESHAKER\"J:\DESHAKER\5 second.MTS".deshake.bat "J:\DESHAKER\5 second.MTS".avi
if exist "J:\DESHAKER\5 second.MTS".part3.avs J:\DESHAKER\VirtualDub\deshakecut.bat "J:\DESHAKER\5 second.MTS".avi.avi


Look where the quotations are, they are not around the complete filename. I actually didnt want them at all.

What could be the cause for this?

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Sometimes I get "" Sometimes not

#2 Post by !k » 01 Mar 2011 12:56

The white spaces.
Use

Code: Select all

"%~1.part1.avs"

zzyzxroad
Posts: 3
Joined: 01 Mar 2011 12:12

Re: Sometimes I get "" Sometimes not

#3 Post by zzyzxroad » 01 Mar 2011 13:45

Ahh, a space!

Ok, but before I go and change several lines of code, if I use "%~1" and the filename doesnt have an space, will it still work?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Sometimes I get "" Sometimes not

#4 Post by aGerman » 01 Mar 2011 14:52

Yes, it will.

My recommendations:
-always enclose pathes in double quotes to protect you from errors caused by spaces
-write redirections in an opposite style to protect you from errors caused by numbers on the line end
-use EnableDelayedExpansion to protect you from errors caused by special characters (e.g. jekyll & hyde.MTS)

Try

Code: Select all

set "file=%~1"

setlocal enabledelayedexpansion

>"J:\DESHAKER\VirtualDub\Picker.bat" echo if exist "!file!.part1.avs" "J:\DESHAKER\VirtualDub\deinterlace1.bat" "!file!"
>>"J:\DESHAKER\VirtualDub\Picker.bat" echo if exist "!file!.part2.avs" "J:\DESHAKER\!file!.deshake.bat" "!file!.avi"
>>"J:\DESHAKER\VirtualDub\Picker.bat" echo if exist "!file!.part3.avs" J:\DESHAKER\VirtualDub\deshakecut.bat" "!file!.avi.avi"

endlocal


Regards
aGerman

zzyzxroad
Posts: 3
Joined: 01 Mar 2011 12:12

Re: Sometimes I get "" Sometimes not

#5 Post by zzyzxroad » 02 Mar 2011 13:25

I tried it but the dos promt writes everythiing super fast and never stops. It just keeps writing the same commands.

EDIT: No wait, it works! I had to change a few things with EXIT and GOTO:EOF


Thanks for the help!!!

Post Reply