用戶登錄  |  用戶注冊
首 頁源碼下載網絡學院最新源碼源碼排行屏蔽廣告
當前位置:新興網絡 > 網絡學院 > 編程開發 > Visual Basic

VB 不用API實現創建多層文件夾

減小字體 增大字體 作者:佚名  來源:本站整理  發布時間:2011-02-04 10:52:41

VB 不用API實現創建多級目錄的函數:

VBScript code復制代碼
Option Explicit

Public Function CreateDir(path As String) As Boolean

    Static start, pos As Integer
    Static directory As String
    Static result As Boolean
    result = True
   
    ' initialize the error trap
    On Error GoTo errCreation
   
    ' if null string why bother....
    If path = "" Then Err.Raise vbObjectError + 1
   
    ' start will always be null
    ' the first time through
    If start = Empty Then
        start = 1
    Else
         start = pos + 1
    End If
               
    ' find "\"  if the char exists
    pos = InStr(start, path, Chr$(92))
       
    If (pos <> 0) Then
        ' not at the last directory in the path string...
        directory = directory + Mid$(path, start, pos - start) + Chr$(92)
        If InStr(1, Mid$(path, start, pos - start), Chr$(58)) = 0 And Dir(directory, vbDirectory) = "" Then
           MkDir Mid$(directory, 1, Len(directory) - 1)
        End If
        ' call itself
        result = CreateDir(path)
    ElseIf (pos = 0) Then
        ' the last directory or the only in the path string
        directory = directory + Mid$(path, start, Len(path) - start + 1)
        MkDir Mid$(directory, 1, Len(directory))
        directory = ""
    End If
       
    ' success return true
    CreateDir = result
   
Exit Function

' if it gets here, an exception was thrown
' propogate the error to the calling function
errCreation:
    Err.Clear
    result = False
    CreateDir = result
       
End Function

 

Tags:VB 目錄 文件夾 API

作者:佚名
  • 好的評價 如果您覺得此文章好,就請您
      0%(0)
  • 差的評價 如果您覺得此文章差,就請您
      0%(0)

網絡學院評論評論內容只代表網友觀點,與本站立場無關!

   評論摘要(共 0 條,得分 0 分,平均 0 分) 查看完整評論
175哪个门派赚钱快