|
Sub 读取文件名路径()
Set d = CreateObject("scripting.dictionary")
Set dd = CreateObject("scripting.dictionary")
Set fso = CreateObject("scripting.filesystemobject")
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Folder"
.InitialFileName = "c:\"
If .Show Then
路径 = .SelectedItems(1)
Else
Exit Sub
End If
End With
r = Cells(Rows.Count, 3).End(3).Row
arr = [c1].Resize(r, 2)
For j = 2 To UBound(arr)
If Len(arr(j, 1)) > 0 Then
dd(arr(j, 1) & "") = ThisWorkbook.Path & "\" & arr(j, 2) & "\"
End If
Next j
Call Getfd(路径, fso, d)
With CreateObject("vbscript.regexp")
.Pattern = Join(dd.keys, "|")
.Global = True
For Each k In d.keys
For Each m In .Execute(fso.getbasename(k))
fso.CopyFile k, dd(m.Value), True
Next
Next k
End With
Application.ScreenUpdating = True
End Sub
Sub Getfd(ByVal 路径, fso, d)
Set ff = fso.GetFolder(路径)
For Each f In ff.Files
d(f & "") = ""
Next f
For Each fd In ff.subfolders
Call Getfd(fd, fso, d)
Next fd
End Sub |
|