Home All Groups Group Topic Archive Search About

create directory using UNC path

Author
30 Jan 2006 3:53 PM
arno
Hi,

I am having difficulty with achieving the following:

I have a UNC path, say \\machine\dir1\dir2\dir3

I want to:
1. check if it exists
2. if not, create it.

The first thing is not a prob, but I am having problems with the
second. I have looked in to MkDir (which I was advised to avoid using)
and tried using the FileSystemObject without success. I already have a
routine that creates (nested) folders for me, that uses the
CreateDirectory API, but it cant handle UNC paths.

Any input is appreciated,

kind regards,
arno

Author
30 Jan 2006 6:32 PM
Jay Taplin
Funny thing... I just created this for myself last week!  It utilizes
the FSO, so you'll need a reference to Windows Script Host Object
model.

Public Sub CreateFolder(FolderPath As String)
    Dim fso As IWshRuntimeLibrary.FileSystemObject

    Set fso = New IWshRuntimeLibrary.FileSystemObject

    If Not fso.FolderExists(FolderPath) Then
        If Not fso.FolderExists(fso.GetParentFolderName(FolderPath))
Then
            CreateFolder fso.GetParentFolderName(FolderPath)
        End If
    End If

    fso.CreateFolder FolderPath

    Set fso = Nothing
End Sub

Jay Taplin [MCP - VB]
Author
30 Jan 2006 7:34 PM
arno
Thanks Jay, your code does do the trick. However, as you say, it
requires a reference to the scripting host. I would like to not
include that dependency. Any pointers as to how to go about?

kind regards,
arno

On 30 Jan 2006 10:32:35 -0800, "Jay Taplin"
<jaytap***@integraware.com> wrote:

Show quoteHide quote
>Funny thing... I just created this for myself last week!  It utilizes
>the FSO, so you'll need a reference to Windows Script Host Object
>model.
Author
30 Jan 2006 9:52 PM
Harry Strybos
Show quote Hide quote
"arno" <rNOSPAMnospam@xs4all.nl> wrote in message
news:45dst119v64r3q5e9k5p7pr10hi3okf45u@4ax.com...
> Hi,
>
> I am having difficulty with achieving the following:
>
> I have a UNC path, say \\machine\dir1\dir2\dir3
>
> I want to:
> 1. check if it exists
> 2. if not, create it.
>
> The first thing is not a prob, but I am having problems with the
> second. I have looked in to MkDir (which I was advised to avoid using)
> and tried using the FileSystemObject without success. I already have a
> routine that creates (nested) folders for me, that uses the
> CreateDirectory API, but it cant handle UNC paths.
>
> Any input is appreciated,
>
> kind regards,
> arno

Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal
lpPath As String) As Long