Hi, Im making a program with a textbox were the user enteres a folder, but if the folder doesn't exist they get an error.
anyone know how to check if the folder exists?
Thanks! :)
Printable View
Hi, Im making a program with a textbox were the user enteres a folder, but if the folder doesn't exist they get an error.
anyone know how to check if the folder exists?
Thanks! :)
Does this help?Quote:
Originally Posted by Durthor
Hope this helps...Code:'Returns a boolean - True if the folder exists
Public Function DirExists(MyFile As String)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
DirExists = fs.folderexists(MyFile)
End Function
how to use? :oQuote:
Originally Posted by koolsid
Does this help?
Code:'Paste this in a module
Public Function DirExists(Myfile As String)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
DirExists = fs.folderexists(Myfile)
End Function
'Paste this either in a module or from whereevr you are calling it...
Sub aaa()
Dim Myfile As String
'Change this with the name of the folder
Myfile = "S:\New Folder"
'if the above folder exists then the msgbox
'below will return true
MsgBox DirExists(Myfile)
End Sub
Thanks!!! works perfectly!!! :D :D :) :)
Another way. Note, if the folder does already exist, it will do nothingCode:Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" _
(ByVal lpPath As String) As Long
Private Sub Command1_Click()
'the will create the directory "c:\this\is\a\test\directory\"
'if it doesn't already exist
MakeSureDirectoryPathExists "c:\this\is\a\test\directory\"
End Sub