Saved Bookmarks
| 1. |
Solve : HELP ME PLEASE!!!...IF command? |
|
Answer» I don`t know what`s wrong... I don`t know what`s wrong... well lets look at: Code: [Select]IF EXIST file.ext GOTO yes IF NOT EXIST file.ext GOTO no :yes ... Exit :no ... Exit You don't need Code: [Select]IF NOT EXIST file.ext GOTO no since THERES no other option so your looking at Code: [Select]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 fileI try it but the IF command don`t work with GOTOare you sure your doing it like this? Code: [Select]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 Code: [Select]@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 promptI 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: Code: [Select]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: Code: [Select]@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: Code: [Select]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)... Code: [Select]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. |
|