Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Folder Exist

Hi guys. Can anyone tell me why this bit of code is not working?

The folder C:\Program Files\PassDLG does not exist on my machine so i would expect to get the msgbox display up but i am getting nothing.

I just cant see whats wrong looks right to me.

Thanks to anyone who can help

Dim folderExists As Boolean

If folderExists = My.Computer.FileSystem.DirectoryExists("C:\Program Files\PassDLG") Then

Else
MsgBox("NOTICE:" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "PasswordDialog Software not installed" & Chr(13) & Chr(10) & "NOTE: The SQL part of this script will FAIL if the software is not installed" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Please see Craig Wallace x6088 with any issues" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "THIS SCRIPT WILL NOW SHUTDOWN UNTIL PasswordDialog SOFTWARE IS INSTALLED", CType(64, MsgBoxStyle), "PLEASE READ , PLEASE READ")
'Me.Close() 'UN COMMENT IF TESTING WITH OUT THE PASSWORD SOFTWARE INSTALLED

End If
[1076 byte] By [cjwallaceUK] at [2007-11-11 10:25:53]
# 1 Re: Folder Exist
My.Computer.FileSystem.DirectoryExists returns False, because the folder does not exist. Boolean variables default to False, so fileExists = False. The line:

If folderExists = My.Computer.FileSystem.DirectoryExists...

is equivalent to:

If False = False...

Since False does equal False, the If statement is True and your message box is not displayed. I think you meant to do this:

Dim folderExists As Boolean
If My.Computer.FileSystem.DirectoryExists("C:\Program Files\PassDLG") Then
folderExists = True
Else
MsgBox(...)
End If
Phil Weber at 2007-11-11 20:47:49 >
# 2 Re: Folder Exist
Hi mate. Thanks for taking the time to point out my mistake. Thank you
cjwallaceUK at 2007-11-11 20:48:52 >