Computer Hope
Microsoft => Microsoft DOS => Topic started by: Xeneinxe14 on May 21, 2009, 10:40:17 PM
-
I don`t know what`s wrong...
-----------------------------------------------------------
IF EXIST file.ext (GOTO yes) ELSE (GOTO no)
:yes
...
Exit
:no
...
Exit
-----------------------------------------------------------
or the other way...
-------------------------------------------
IF EXIST file.ext GOTO yes
IF NOT EXIST file.ext GOTO no
:yes
...
Exit
:no
...
Exit
-------------------------------------------
Somebody can help me whit these batch`s files...
:P sorry for my english!
-
I don`t know what`s wrong...
-----------------------------------------------------------
IF EXIST file.ext (GOTO yes) ELSE (GOTO no)
:yes
...
Exit
:no
...
Exit
-----------------------------------------------------------
or the other way...
-------------------------------------------
IF EXIST file.ext GOTO yes
IF NOT EXIST file.ext GOTO no
:yes
...
Exit
:no
...
Exit
-------------------------------------------
Somebody can help me whit these batch`s files...
:P sorry for my english!
well lets look at:
IF EXIST file.ext GOTO yes
IF NOT EXIST file.ext GOTO no
:yes
...
Exit
:no
...
Exit
You don't need
IF NOT EXIST file.ext GOTO no
since theres no other option
so your looking at
IF EXIST file.ext GOTO yes
goto no
so if it exists, goto yes, if it doesn't it will continue the script and goto no
ALSO.
you might want to add in the directory of the file
-
I try it but the IF command don`t work with GOTO
-
are you sure your doing it like this?
if exist c:\windows\myfile.txt goto yes
goto no
well try this code out, except replace myfile.txt with the name of your file
@echo off
if exist c:\windows\myfile.txt goto yes
goto no
:yes
echo Worked
pause
exit
:no
echo didn't work
pause
exit
-
The original .bat be...
-----------------------------------------------
IF EXIST autorun.inf GOTO yes
goto no
:yes
ren ....
del...
exit
:no
echo...
set /p...
...etc...
exit
---------------------------------------------------
but the shell show me something like this
"The command`s syntax is incorrect"
-
thats interesting.
well lets see the full error:
open up command prompt
type the full path and name of your batch
c:\path of file\file.bat
and press enter.
and it should say the error then resume to command prompt
-
I don`t understand why appear the message "The syntax of the command is incorrect"...I follow you step to step....fu___ batch >:(
-
well there goes my ideas.
the if syntax shouldn't have any problems with exist.
so if anyone else wants to try and help. please
-
(1) If the file is not in the same folder as the batch file you need to use the full path.
(2) If the file name and/or path has one or more spaces you need quote marks before and after it. They do not do any harm if there are no spaces.
(3) Contents of folder:
S:\Test\Batch\ifexist>dir
Volume in drive S is USBHD
Volume Serial Number is 2C51-AA7F
Directory of S:\Test\Batch\ifexist
22/05/2009 07:40 <DIR> ..
22/05/2009 07:40 <DIR> .
22/05/2009 07:40 7 test.txt
22/05/2009 07:43 137 test.bat
2 File(s) 144 bytes
(4) test.bat:
@echo off
if exist "test.txt" (goto yes) else (goto no)
:yes
echo file exists
goto end
:no
echo file does not exist
:end
pause
(5) Output on screen:
S:\Test\Batch\ifexist>test.bat
file exists
Press any key to continue . . .
(6) I edited test.bat: I changed if exist test.txt to if exist test1.txt (which does not exist)...
S:\Test\Batch\ifexist>test.bat
file does not exist
Press any key to continue . . .
-
Can the OP show which command line is causing the error or is it just assumed that it's the If exist command line?
-
OK tanks everybody...but, for example I have in a directory named "Test" the next files: autorun .inf, autorunH.inf and the batch.
The batch cotains the next commands:
-----------------------------------------------------------------------------------
@echo off
IF exist "Autorun.inf" (GOTO yes) ELSE (GOTO no)
:yes
ren %USERPROFILE%\desktop\test\Autorun.inf Autorun1.inf
ren %USERPROFILE%\desktop\test\AutorunH.inf Autorun.inf
pause
Exit
:no
ren %USERPROFILE%\desktop\test\AutorunH.inf Autorun.inf
pause
Exit
------------------------------------------------------------------------------------
but the batch file doesn`t works cause appear the same message ervery time "The syntax of the command is incorrect"...
What is it OP?
-
1. You didn't take any notice of what I wrote about paths and filenames with spaces in them.
2. The OP is you. Original Poster.