By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

How to determine if directory exists

P: n/a
TTD
Hello,

I need to create a directory in code, but when de directory already exists,
I get err.number 75.

Since the creation already is in the part where a former error is sent, I
can't catch this error.

In VB there is this code
path = "C:\temp\"
If Directory.Exists(path) = False Then
' Create the directory.
Directory.CreateDirectory(path)
End If

Is there a way to determine if C:\temp already exists before I create one?

Thanks for your time.
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Rog
if len(dir(path)) = 0 then
'create the directory
end if

Nov 13 '05 #2

P: n/a
Might be good to use the vbDirectory argument of Dir():

Public Function FolderExists(varPath As Variant) As Boolean
On Error Resume Next
If Len(varPath) > 0 Then
FolderExists = (Len(Dir$(varPath, vbDirectory)) > 0&)
End If
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Rog" <ro************@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
if len(dir(path)) = 0 then
'create the directory
end if

Nov 13 '05 #3

P: n/a
Tried that as well. Sorry!

Dawn
"TTD" <tt*@hotmail.com> wrote in message
news:42*********************@diablo.nl.easynet.net ...
Hello,

I need to create a directory in code, but when de directory already
exists,
I get err.number 75.

Since the creation already is in the part where a former error is sent, I
can't catch this error.

In VB there is this code
path = "C:\temp\"
If Directory.Exists(path) = False Then
' Create the directory.
Directory.CreateDirectory(path)
End If

Is there a way to determine if C:\temp already exists before I create one?

Thanks for your time.

Nov 13 '05 #4

P: n/a
Allen Browne wrote:
Might be good to use the vbDirectory argument of Dir():

Public Function FolderExists(varPath As Variant) As Boolean
On Error Resume Next
If Len(varPath) > 0 Then
FolderExists = (Len(Dir$(varPath, vbDirectory)) > 0&)
End If
End Function


Another method I've used in the past (Before BASIC could find
direcrtories) is to append \nul [1] to the path as the nul device exists
in any valid path.

[1] Note in an OS nul is spelt with a single l, not "null" as in Access'

--
[OO=00=OO]
Nov 13 '05 #5

P: n/a
Trevor Best wrote:
Allen Browne wrote:
Might be good to use the vbDirectory argument of Dir():

Public Function FolderExists(varPath As Variant) As Boolean
On Error Resume Next
If Len(varPath) > 0 Then
FolderExists = (Len(Dir$(varPath, vbDirectory)) > 0&)
End If
End Function


Another method I've used in the past (Before BASIC could find
direcrtories) is to append \nul [1] to the path as the nul device exists
in any valid path.

[1] Note in an OS nul is spelt with a single l, not "null" as in Access'


Actually, this may be the safer option, as vbDirectory will find files
as well as directories, you could very well find a file that you thought
was a directory.

--
[OO=00=OO]
Nov 13 '05 #6

P: n/a
dim bExists as boolean

bExists = FileExistsDir("path")

if bExist = False
'create directory
end if
Function FileExistsDIR(sFile As String) As Boolean
FileExistsDIR = True
If Dir$(sFile) = vbNullString Then FileExistsDIR = False
End Function

Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.