Option Explicit
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long
Private Sub Command1_Click()
'注意路徑要以 \ 結束,路徑校驗的代碼自己寫'
MakeSureDirectoryPathExists Text1.Text
End Sub
以上用不了
哪個高手指點下是怎么回事
能回答個全部的代碼嗎。
uj5u.com熱心網友回復:
mkdir建檔案夾,自己百度。
uj5u.com熱心網友回復:
大概的代碼,請參考:Option Explicit
Sub test()
Dim w1 As String
w1 = CreatePath(Text1.Text)
If w1 <> "" Then MsgBox w1
End Sub
Function CreatePath(ByVal bPath As String) As String
CreatePath = "請輸入正確的路徑!" ''''給一個默認的錯誤資訊
bPath = Trim(bPath)
If Len(bPath) = 0 Then Exit Function
bPath = bPath & "\"
On Error GoTo errs
Dim s1 As String, i As Integer, s2 As String, pp
pp = Split(bPath, "\")
If UBound(pp) > 1 Then
s1 = pp(0)
For i = 1 To UBound(pp) - 1
s2 = Trim(pp(i))
If s2 = "" Then Exit Function
s1 = s1 & "\" & s2
If Dir$(s1, vbDirectory) = "" Then MkDir s1
Next
End If
CreatePath = ""
Exit Function
errs:
CreatePath = Err.Description
End Function
...
uj5u.com熱心網友回復:
這代碼看著也沒問題,好幾年前就看到過類似這樣應用的代碼了。
我試了一下用它創建兩級不存在的檔案夾,也都創建成功了的。
e:\code\T1\T2\
路徑中e:\code是已經存在的,T1、T2是不存在的,運行后創建成功了。
樓主你說“不行”,它有沒有什么錯誤提示,要說清楚啊 !!!
uj5u.com熱心網友回復:
我的系統:Windows 7 SP1旗艦版,64位VB6是簡體中文企業版。
代碼是在VB6的IDE下運行了一下。
uj5u.com熱心網友回復:
就是我給的代碼 VB創建用EXT1內容命名的多級檔案夾代碼怎么寫代碼本身是不會有問題的。
你輸入的路徑不對?
在上級目錄中沒有權限?
被殺毒軟體阻止了?
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/65426.html
標籤:VB基礎類
下一篇:請教一下這個報表用SQL怎么弄
