devxlogo

Create Multiple Levels of Directories

Create Multiple Levels of Directories

If your users have the option to type a directory where they wantfiles installed, they may type a directory that doesn’t existor a directory that is several levels below another directory.

This procedure checks to see if the directory exists and createsit if it doesn’t. No matter how long the request, it will createany and all directories. This procedure allows users to createlong directory names in VB4, but truncates each directory to 8.3characters in VB3. The only requirements are that sDrive be passedas “:” (i.e. “C:”) and that sDirbe formatted as “” (i.e. “Dir1Dir2”).Add your own error handling to make sure these elements existproperly.

Here is an example of creating a directory several levels deepand 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        WendEnd SubSub Test()        Call CreateLongDir("C:", _                "TestTestDirLong Directory _                Name")End Sub
See also  lenso.ai - an AI reverse image search platform
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist