Page 1 of 1
Use if exist to check for folder and if not change to diff 1
Posted: 18 Jul 2012 12:35
by Lateralus138
I'm not sure if I can do this, I am trying to make a batch file that checks to see if a folder exists and if it does cd to that folder, but if it does not it cd to another folder. More specifically on a 64 bit system checks for Program Files (x86) and if not goes to Program Files. I want to make a batch that my friends and I can use wget to download files without a browser being open and without having to use a bulky 3rd party software. If on a 64 bit system the folder will be located in x86 and if not in the regular program files and I want it to check which and cd to that folder then a user can input the link and download location. I can do the user input and variables I am just having trouble learning how to correctly and effectively use if exist. The code below is what I came up with and I know it's wrong, but it shows some of what I am trying to do.
Code: Select all
if exist %programfiles(x86)% (
cd %programfiles(x86)%
) else (
goto a
)
goto b
:a
cd "%programfiles%"
:b
Re: Use if exist to check for folder and if not change to di
Posted: 18 Jul 2012 12:48
by foxidrive
Modify the paths to suit.
Code: Select all
@echo off
if exist "foldera\wget\wget.exe" cd /d "foldera\wget\"
if exist "folderb\wget\wget.exe" cd /d "folderb\wget\"
if not exist wget.exe (
echo wget was not found
pause
goto :EOF
)
rem do wget stuff here.
Re: Use if exist to check for folder and if not change to di
Posted: 18 Jul 2012 12:57
by Lateralus138
foxidrive wrote:Modify the paths to suit.
Code: Select all
@echo off
if exist "foldera\wget\wget.exe" cd /d "foldera\wget\"
if exist "folderb\wget\wget.exe" cd /d "folderb\wget\"
if not exist wget.exe (
echo wget was not found
pause
goto :EOF
)
rem do wget stuff here.
OK, thanx so if it checks for a file and it doesn't exist it will go to the end of the file, but it is found then it skips past the goto :EOF and moves on the the next part?
Re: Use if exist to check for folder and if not change to di
Posted: 18 Jul 2012 13:35
by foxidrive
Lateralus138 wrote:OK, thanx so if it checks for a file and it doesn't exist it will go to the end of the file, but it is found then it skips past the goto :EOF and moves on the the next part?
Yes. When you do the checking for folders - do the 64 bit folder second. If wget exists in both locations then it will use the 64 bit one.