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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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?
Answered 11/05/2009 by: VBScab
Red Belt

Please log in to comment
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
Answered 11/05/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
0
So:

- did you try adding 'nul'?
- when is the project leader scheduled for his lobotomy?
Answered 11/05/2009 by: VBScab
Red Belt

Please log in to comment
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%

)
Answered 11/05/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
0
That's a "No", then. I tried, I really did...
Answered 11/05/2009 by: VBScab
Red Belt

Please log in to comment
0
oh!
Is this logic wrong? or we can do it in better way?
Answered 11/05/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
0
Answered 11/05/2009 by: VBScab
Red Belt

Please log in to comment
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
Answered 11/05/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
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
Answered 11/05/2009 by: pjgeutjens
Red Belt

Please log in to comment
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
Answered 11/05/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
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
Answered 11/05/2009 by: pjgeutjens
Red Belt

Please log in to comment
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
Answered 11/05/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
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
Answered 11/06/2009 by: pjgeutjens
Red Belt

Please log in to comment
0
Great man...your logic is simpler, and better...as well as it is working fine.
Thanks to VBScab also. [:)]

cheers!
Answered 11/06/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
Answer this question or Comment on this question for clarity