Reputation: 13
I need to make a Windows batch file that will:
1.- Check a directory name and "If" it exists, a.- Run a specified *.exe from a different directory.
2.- Or "Else" a.- Rename a directory and also b.- Rename another directory - then c.- Run a *.exe from the created directory.
Question is: I'm stuck on the correct syntax ( I suppose) on creating this batch file. This is what I have, (maybe a nested if/Else would be better?) someone please enlighten me... Thanks.
@echo off
IF EXIST "C:\Test\Dir1" (
START "C:\Test\Dir\Test.exe"
) ELSE ( ren "C:\Test\Dir" "C:\Test\Dir1"
ren "C:\Test\Dir2" "C:\Test\Dir"
START "C:\Test\Dir\Test.exe"
)
Upvotes: 1
Views: 786
Reputation: 13
Thanks dbenham and Magoo. Your responses made a world of difference on something that seems quite simple. It is now working as all the changes you both mentioned help. The final "nail in the coffin" was understanding the syntax for the START parameters. Understanding that the first parameter has double quotes and it uses that as the optional TITLE for the new window, ssoooo giving it an empty double quote ( "" ) gives it an empty title before the name of the program to fake it out. And Voila...
Thank you guys sssooo much. Final Working batch file.
@echo off
IF EXIST "C:\Test\Dir1" (
START "" "C:\Test\Dir\Test.exe"
) ELSE ( ren "C:\Test\Dir" "Dir1"
ren "C:\Test\Dir2" "Dir"
START "" "C:\Test\Dir\Test.exe"
)
Upvotes: 0
Reputation: 80113
You can't ren
with a target name including a path or drive.
try
ren "C:\Test\Dir2" "Dir"
start
has odd syntax - 'though it seems to not be the problem in this case. The first "quoted argument" string becomes the window title and can be routinely disregarded by the executable. Try
routinely using
start "window title that can be empty if you like" "executablename" argument list
Even if this arguably doesn't comply exactly with the documented behaviour.
(and simplifying problems to a generality can obscure the real cause, too)
Upvotes: 1