Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if folder is present

Status
Not open for further replies.

deltaair

IS-IT--Management
Nov 3, 2005
43
CH
any way to code a subroutine to check if a folder is present or not. i know how to make the folder, but it doesn;t work if its already there...
 
If Dir(strDirPath, vbDirectory) <> "" Then
MsgBox strDirPath & " already exists"
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I'm not sure if this is 'best practice', but I usually use something like this:
Code:
...

[green]'   Create new folder if necessary[/green]
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
objFSO.CreateFolder _
    "C:\SubFolder\" & Format(now(), "yyyy-mm") & "\"
On Error GoTo 0
Set objFSO = Nothing

...

[tt]_____
[blue]-John[/blue][/tt]

Help us help you. Please read FAQ181-2886 before posting.
 
And here my own procedure (emulating the mkdir -p unix command):
Sub myMkDir(strFolderName As String)
On Error Resume Next
Dim a, t As String, i As Integer
a = Split(strFolderName, "\")
t = a(0)
For i = 1 To UBound(a)
t = t & "\" & a(i)
MkDir t
Next
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top