Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Networks on November 27, 2005, 09:46 AM

Title: Creating directories
Post by: Networks on November 27, 2005, 09:46 AM
I understand how to make directories using mkdir() but you will recieve an error if the parent directory of a sub directory you're creating doesn't exist. Simply if I try to create ...\Parent\Sub, Sub will not be created because Parent is not already created. In .NET the CreateDirectory() function will create both on demand vb6 won't. Is there another way? Thank you.
Title: Re: Creating directories
Post by: Yegg on November 27, 2005, 09:51 AM
Why not just create Parent then create Sub? If Parent doesn't already exist that is. Or am I misunderstanding you?
Title: Re: Creating directories
Post by: Networks on November 27, 2005, 09:59 AM
Quote from: Yegg on November 27, 2005, 09:51 AM
Why not just create Parent then create Sub? If Parent doesn't already exist that is. Or am I misunderstanding you?

That requires parsing through a string I don't feel like parsing through but if I have to I will, right now I want to see if it's possible to do it all together.
Title: Re: Creating directories
Post by: l)ragon on November 27, 2005, 05:07 PM
    If Dir(ParentDir) = "" Then 'Parent dir does not exist
        'Make the parent directory
    Else                        'Parent dir exists
        '
    End If
   
    If Dir(ChildDir) = "" Then  'Child dir does not exist
        'Make the child directory
    Else                        'Child dir exists
        '
    End If

How is that so hard 8\


Edit: here
Public Function DirExists(ByVal strFolder As String) As Boolean
    If Dir(strFolder) = "" Then 'Dir does not exist
        DirExists = False
    Else                        'Dir exists
        DirExists = True
    End If
End Function
Title: Re: Creating directories
Post by: Yegg on November 27, 2005, 07:03 PM
Quote from: l)ragon on November 27, 2005, 05:07 PM
    If Dir(ParentDir) = "" Then 'Parent dir does not exist
        'Make the parent directory
    Else                        'Parent dir exists
        '
    End If
   
    If Dir(ChildDir) = "" Then  'Child dir does not exist
        'Make the child directory
    Else                        'Child dir exists
        '
    End If

How is that so hard 8\
That's what I was wondering. But what I think he is looking for is a function (or other method) that does this for him. But any other method would still in turn have to parse the string. So what I would do is simply parse it on my own.
Title: Re: Creating directories
Post by: rabbit on November 27, 2005, 08:07 PM
Check out the MakeSureDirectoryPathExists() API.
Title: Re: Creating directories
Post by: Networks on November 28, 2005, 03:56 PM
I meant creating a directory such as:
C:/Test/Test2

...where parent directory Test doesn't exist and could be anything (user input). Test2 could also be anything.
Title: Re: Creating directories
Post by: rabbit on November 28, 2005, 07:25 PM
MakeSureDirectoryPathExists() creates the entire path, if it does not exist.
Title: Re: Creating directories
Post by: Networks on November 28, 2005, 11:05 PM
Quote from: rabbit on November 28, 2005, 07:25 PM
MakeSureDirectoryPathExists() creates the entire path, if it does not exist.

Why can't I find that declaration in the API test viewer for VB6?
Title: Re: Creating directories
Post by: FrOzeN on November 28, 2005, 11:19 PM
After a quick google search, I found this (http://www.developersdex.com/vb/message.asp?p=640&r=4178633).

It cover's the gist of what you want.
Title: Re: Creating directories
Post by: PaiD on November 29, 2005, 12:46 PM
This (http://mentalis.org/apilist/MakeSureDirectoryPathExists.shtml) tells about the API