Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Expertise: Beginner
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Create Multiple Levels of Directories

If your users have the option to type a directory where they want files installed, they may type a directory that doesn't exist or a directory that is several levels below another directory.

This procedure checks to see if the directory exists and creates it if it doesn't. No matter how long the request, it will create any and all directories. This procedure allows users to create long directory names in VB4, but truncates each directory to 8.3 characters in VB3. The only requirements are that sDrive be passed as "<drive>:" (i.e. "C:") and that sDir be formatted as "\<directory>\" (i.e. "\Dir1\Dir2\"). Add your own error handling to make sure these elements exist properly.

Here is an example of creating a directory several levels deep and using a long directory name:

Sub CreateLongDir(sDrive As String, _
        sDir As String)
        Dim sBuild As String

        While InStr(2, sDir, "\") > 1
                sBuild = sBuild & Left$(sDir, _
                        InStr(2, sDir, "\") - 1)
                sDir = Mid$(sDir, InStr(2, _
                        sDir, "\"))
                If Dir$(sDrive & sBuild, 16) = _
                        "" Then
                        MkDir sDrive & sBuild
                End If
End Sub

Sub Test()
        Call CreateLongDir("C:", _
                "\Test\TestDir\Long Directory _
End Sub

Jeffrey Renton
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date