Check folder exists
Hi,
I want to check existence of folder, and if it does not exist, then my script should check another folder. there is bug in my bat - script, i am not able to find it.
In below script, if folder exist and if folder does not exist, in both the cases, it is showing echo message.
I want to check existence of folder, and if it does not exist, then my script should check another folder. there is bug in my bat - script, i am not able to find it.
In below script, if folder exist and if folder does not exist, in both the cases, it is showing echo message.
@echo off
Setlocal
Set current=%~dp0
set path1="%systemroot%\Microsoft.NET\Framework\v2.0.50727"
set path2="%systemroot%\Microsoft.NET\Framework\v3.0"
set path3="%systemroot%\Microsoft.NET\Framework\v3.5"
if not exist "%path1%" GOTO TEST1
:TEST1
ECHO ABSENT
Pause
0 Comments
[ + ] Show comments
Answers (14)
Please log in to answer
Posted by:
pjgeutjens
15 years ago
How about something like this?
IF EXIST C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\NUL GOTO INSTALLMSI
IF EXIST C:\WINDOWS\Microsoft.NET\Framework\v3.0\NUL GOTO INSTALLMSI
IF EXIST C:\WINDOWS\Microsoft.NET\Framework\v3.5\NUL GOTO INSTALLMSI
ECHO Install Dotnet
:INSTALLMSI
ECHO Install your-msi
PAUSE
Posted by:
anonymous_9363
15 years ago
Posted by:
abking99
15 years ago
My project std is using batfile. I have already written vbscript for the same.
path1 = strsystemroot & "\Microsoft.NET\Framework\v2.0.50727"
path2 = strsystemroot & "\Microsoft.NET\Framework\v3.0"
path3 = strsystemroot & "\Microsoft.NET\Framework\v3.5"
If fso.folderexists (path1)=0 AND fso.folderexists (path2)=0 AND fso.folderexists (path3)=0 then
i = WshShell.run (pre1,1,true)
end if
Posted by:
anonymous_9363
15 years ago
Posted by:
abking99
15 years ago
@echo off
Setlocal
Set current=%~dp0
set path1="%systemroot%\Microsoft.NET\Framework\v2.0.50727"
set path2="%systemroot%\Microsoft.NET\Framework\v3.0"
set path3="%systemroot%\Microsoft.NET\Framework\v3.5"
if not exist "%path1%" (
goto test1
) else (
ECHO Command to Install msxml
ECHO Command to Install your-msi
exit %errorlevel%
)
:test1
if not exist "%path2%" (
goto test2
) else (
ECHO Command to Install msxml
ECHO Command to Install your-msi
exit %errorlevel%
)
:test2
if not exist "%path3%" (
ECHO Command to Install Dotnet
ECHO Command to Install msxml
ECHO Command to Install your-msi
exit %errorlevel%
)else (
ECHO Command to Install msxml
ECHO Command to Install your-msi
exit %errorlevel%
)
Posted by:
abking99
15 years ago
I know I am wrong, in below code, I used logic which you are expecting. Problem is if folder exists or not exists it goes to :test1 and shows echo.
@echo off
Setlocal
Set current=%~dp0
set path1="%systemroot%\Microsoft.NET\Framework\v2.0.50727\NUL"
set path2="%systemroot%\Microsoft.NET\Framework\v3.0"
set path3="%systemroot%\Microsoft.NET\Framework\v3.5"
if not exist C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\NUL GOTO TEST1
:TEST1
ECHO ABSENT
PAUSE
Posted by:
pjgeutjens
15 years ago
just off the top of my head here...
maybe put an EXIT before the :TEST1, cause what happens now is:
file does not exist -> goes to :TEST1
file does exist -> do nothing and go to next line which is... :TEST1 (tadaa)
and like Ian said, what are you doing messing around with batch files in the first place?
PJ
if not exist C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\NUL GOTO TEST1
:TEST1
ECHO ABSENT
PAUSE
maybe put an EXIT before the :TEST1, cause what happens now is:
file does not exist -> goes to :TEST1
file does exist -> do nothing and go to next line which is... :TEST1 (tadaa)
and like Ian said, what are you doing messing around with batch files in the first place?
PJ
Posted by:
abking99
15 years ago
Hi vbscab, and pjgeutjens, do u mean below logic...
@echo off
Setlocal
Set current=%~dp0
if not exist C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\NUL GOTO TEST1
ECHO Install msxml1
ECHO Install your-msi1
PAUSE
Exit
:TEST1
if not exist C:\WINDOWS\Microsoft.NET\Framework\v3.0\NUL GOTO TEST2
ECHO Install msxml2
ECHO Install your-msi2
PAUSE
Exit
:TEST2
if not exist C:\WINDOWS\Microsoft.NET\Framework\v3.5\NUL GOTO TEST3
ECHO Install msxml3
ECHO Install your-msi3
PAUSE
Exit
:TEST3
ECHO Install Dotnet
ECHO Install msxml4
ECHO Install your-msi4
PAUSE
Exit
Posted by:
pjgeutjens
15 years ago
Posted by:
abking99
15 years ago
Posted by:
abking99
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.