/build/static/layout/Breadcrumb_cap_w.png

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.



@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)

Posted by: pjgeutjens 14 years ago
Red Belt
2
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 14 years ago
Red Belt
0
Scratching around the depths of my memory here but don't you have to test 'nul' for folder existence? As inif exist c:\test\nul goto whatever

Why do this nonsense in batch, anyway, when VBScript is light years more capable?
Posted by: abking99 14 years ago
Second Degree Blue Belt
0
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 14 years ago
Red Belt
0
So:

- did you try adding 'nul'?
- when is the project leader scheduled for his lobotomy?
Posted by: abking99 14 years ago
Second Degree Blue Belt
0

@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: anonymous_9363 14 years ago
Red Belt
0
That's a "No", then. I tried, I really did...
Posted by: abking99 14 years ago
Second Degree Blue Belt
0
oh!
Is this logic wrong? or we can do it in better way?
Posted by: abking99 14 years ago
Second Degree Blue Belt
0
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 14 years ago
Red Belt
0
just off the top of my head here...


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 14 years ago
Second Degree Blue Belt
0
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 14 years ago
Red Belt
0
tbh I don't have a clue what you're actually trying to do, just make sure your script doesn't fall through to the same GOTO points whatever the outcome of your checks is.

and P.S. goto scripting makes me shiver violently [:'(]

PJ
Posted by: abking99 14 years ago
Second Degree Blue Belt
0
Actually, my package requires, atleast dotnet 2.0. It will work with 2.0, 3.0, 3.5. So if all three versions are absent then, it should install dotnet and my application
Posted by: abking99 14 years ago
Second Degree Blue Belt
0
Great man...your logic is simpler, and better...as well as it is working fine.
Thanks to VBScab also. [:)]

cheers!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ