|
- Option Explicit
- Private Fso As Object, Mypath As String
- Public r As Integer
- Sub 选择文件夹()
- Dim Fo
-
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择要批量重命名文件的文件夹"
- .Show
- If .SelectedItems.Count = 0 Then Exit Sub
- 'MsgBox .SelectedItems.Count
- MsgBox .SelectedItems(1)
- Mypath = .SelectedItems(1) & ""
- End With
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Fo = Fso.getfolder(Mypath)
- r = Range("A65536").End(xlUp).Row + 1
- Call 递归(Fo)
- End Sub
- Sub 获取文件名(Folder)
- Dim Fi, filename As String
- For Each Fi In Folder.Files
- filename = Fi.Name
- Cells(r, 1) = Folder.Path & ""
- Cells(r, 2) = Fso.getbasename(filename)
- Cells(r, 4) = "." & Fso.GetExtensionName(filename)
- r = r + 1
- Next
- End Sub
- Sub 递归(Folder)
- Dim Fi, Fo
- Call 获取文件名(Folder)
- If Folder.subFolders.Count > 0 Then
- For Each Fo In Folder.subFolders
- Cells(r, 1) = Folder.Path & ""
- Cells(r, 2) = Fo.Name
- r = r + 1
- Call 递归(Fo)
- Next
- End If
- End Sub
复制代码 请老师帮忙看看那里出错了,新WPS2019的运行不了。
|
|