Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Directory

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    In a macro that I have written, I create a new directory. Is it possible to first of all check that a directory with the same name already exists, if it does, not to bother to create the directory and if it does not go ahead and create the directory.

    Hope someone can help

    Thanks

    Matt

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Location
    Calgary Canada
    Posts
    222
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    try this code :
    ''''''''''''''''''''''''''
    Function Test(YourDirectory As String) As Boolean
    Test = False
    TestName = Dir(TestPath, vbDirectory)
    Do While TestName <> ""
    If UCase$(YourDirectory) = UCase$(TestName) Then Test = True: Exit Do
    TestName = Dir ' Get next directory
    Loop
    End Function
    ''''''''''''''''''''''''''''''''''''
    where TestPath = "c:" or your path and YourDirectory is your folder for test.
    Test is true if your folder already exists.
    Good luck!


  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks for the code but I think I am being dumb as I cannot get it to run. I have tried to substitute the path and directory names as suggested, please could you resupply code if my path is C:/ and folder name is Matt.

    Many thanks

    Matt

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Calgary Canada
    Posts
    222
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hello matt,
    sorry for my delay, I had a class.
    copy these code in a module:
    ''''''''''''''''''''''''''''''''''''
    Function Test_Folder(YourDirectory, TestPath) As Boolean
    Test_Folder = False
    GetFolder = Dir(TestPath, vbDirectory)
    Do While GetFolder <> ""
    If UCase$(YourDirectory) = UCase$(GetFolder) Then Test_Folder = True: Exit Do
    GetFolder = Dir ' Get next directory
    Loop
    End Function

    Sub Main_Test()

    ''' enter your path here
    TestPath = "c:"
    '''please enter your folder name
    YourDirectory = "Matt"
    If YourDirectory = "" Then Exit Sub
    If Test_Folder(YourDirectory, TestPath) = True Then
    MsgBox (YourDirectory & " already exists.")
    Else
    MsgBox (YourDirectory & " does not exist.")
    End If

    End Sub
    ''''''''''''''''''''''''''''''''''
    now run Main_Test.
    Good luck!
    Hamid

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hamid

    That's worked, thanks for your help and patience

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •