Advertisement
2002C VB function enhancement #9127

CreateFolders

Make nested subfolders in a single method.

AI

AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ソースコード
original-source
Public Sub CreateFolders(ByVal sPath As String)
 Dim oFileSystem As New Scripting.FileSystemObject
 'or late-bind with:
 'Dim oFileSystem As Object
 'Set oFileSystem = CreateObject("Scripting.FileSystemObject")
 On Error GoTo ErrorHandler
 With oFileSystem
  ' Is this drive valid and ready?
  If .DriveExists(.GetDriveName(sPath)) Then
   ' Is this folder not yet valid?
   If Not .FolderExists(sPath) Then
    ' Recurse back in to this method until a parent folder is valid.
    CreateFolders .GetParentFolderName(sPath)
    ' Create only a nonexistant folder before exiting the method.
     .CreateFolder sPath
   End If
  End If
 End With
 Set oFileSystem = Nothing
ExitMethod:
 Exit Sub
ErrorHandler:
 App.LogEvent "CreateFolders Error in " & Err.Source & _
 ": Could not create " & sPath & ".", vbLogEventTypeInformation
End Sub
オリジナルのコメント (3)
Wayback Machineから復元