- 帖子
- 109
- 主題
- 2
- 精華
- 0
- 積分
- 114
- 點名
- 0
- 作業系統
- Win7 Win10
- 軟體版本
- Office 2019 WPS
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 深圳
- 註冊時間
- 2013-2-2
- 最後登錄
- 2024-11-6
|
回復 Joforn
這VBA執行OK,可是中文檔案名稱回傳變成亂碼,請問這要如何修正,感恩
第一個VBA執行 ...
ML089 發表於 2020-11-11 14:17 
.Path返回的并不是亂碼,而是將文字進行了Url編碼,可以通過Url解碼得到原字符串,也可以用下面的方式直接返回文字格式。- Public Property Get FTPSearch(ByVal FTPUrl As String, _
- Optional ByVal UserName As String, _
- Optional ByVal PassWord As String, _
- Optional ByVal Port As Integer) As Collection
-
- Dim objShell As Object, objFolder As Object
-
- On Error Resume Next
-
- If Len(FTPUrl) Then
- If Len(UserName) Then FTPUrl = UserName & ":" & PassWord & "@" & FTPUrl
- If Port > 0 Then FTPUrl = FTPUrl & ":" & Port
- Set objShell = CreateObject("Shell.Application")
- Set objFolder = objShell.Namespace("FTP://" & FTPUrl)
- End If
- Set FTPSearch = New Collection
- If objFolder Is Nothing Then Exit Function
-
- With objFolder
- If .ParentFolder.Self.IsFolder Then
- If .ParentFolder.ParseName(.Self.Name) Is Nothing Then
- Debug.Print "Error:Invalid Path!"
- ElseIf objFolder.Self.IsBrowsable Then
- Debug.Print "Error:Invalid Parameter!"
- ElseIf objFolder.Self.IsFolder Then
- Debug.Print "Start search files in path..."
- With objFolder
- FTPSearchWithShell FTPSearch, .ParentFolder.ParseName(.Self.Name).GetFolder
- End With
- Debug.Print "Files search completed."
- End If
- ElseIf objFolder.Self.IsFolder Then
- Debug.Print "Start search files in path..."
- With objFolder
- FTPSearchWithShell FTPSearch, objFolder
- End With
- Debug.Print "Files search completed."
- End If
- End With
- End Property
- Private Sub FTPSearchWithShell(ByVal Searched As Collection, ByVal Folder As Object, Optional ByVal strPath As String)
- Dim FolderItem As Object
- Dim objFolder As Object
- Dim subSearch As New Collection
-
- On Error Resume Next
-
- If Len(strPath) = 0 Then
- Set objFolder = Folder
- Do While (objFolder.ParentFolder.Self.IsFolder)
- strPath = objFolder.Self.Name & "/" & strPath
- Set objFolder = objFolder.ParentFolder
- Loop
- strPath = objFolder.Self.Path & strPath
- End If
-
- If Folder.Items.Count > 0 Then
- Set subSearch = New Collection
- For Each FolderItem In Folder.Items
- With FolderItem
- If .IsFolder Then
- Set Folder = .GetFolder
- If Folder.Items.Count Then subSearch.Add Folder
- ElseIf .IsBrowsable Then
- Searched.Add strPath & .Name
- End If
- End With
- Next FolderItem
-
- For Each Folder In subSearch
- FTPSearchWithShell Searched, Folder
- DoEvents
- Next Folder
- End If
- End Sub
- Sub Test()
- Dim Files As Collection
- Dim I As Long
-
- Set Files = FTPSearch("118.163.50.55/firmware_software_version_files/", "xxxxx", "xxxx")
- For I = 1 To Files.Count
- Debug.Print Files.Item(I)
- Next I
- End Sub
複製代碼 |
|