|
楼主 |
发表于 2024-5-11 11:34
|
显示全部楼层
本帖最后由 ning84 于 2024-5-11 16:01 编辑
超级慢
- Sub ll()
- T = Time
- Dim Fso As FileSystemObject
- Set Fso = New FileSystemObject
- Dim oFolder As Folder
- Set oFolder = Fso.GetFolder(ThisWorkbook.Path)
- CreateFolder Fso, oFolder, "D:"
- Debug.Print oFolder.Name, oFolder.Files.Count; Format(Time - T, "h:mm:ss")
- End Sub
- Function CreateFolder(Fso As FileSystemObject, oFolder As Folder, RootPath As String)
- Dim SubFolder As Folder, tFolder As Folder
- Dim oPath As String
-
- For Each SubFolder In oFolder.SubFolders
-
- oPath = Replace(SubFolder.Path, ThisWorkbook.Path, RootPath)
- 'Debug.Print oPath, SubFolder.Path, ThisWorkbook.Path
- If Fso.FolderExists(oPath) = False Then
- Fso.CreateFolder oPath
- With SubFolder
- Debug.Print .Name, .Files.Count, .Files.Count, Format(Time - T, "h:mm:ss")
- End With
- End If
- ''
- If Fso.FolderExists(oPath) Then
- 'Set tFolder = Fso.GetFolder(oPath)
- With SubFolder
- 'Debug.Print .Name, .Files.Count, .Files.Count, Format(Time - T, "h:mm:ss")
- CopyFileToFolder Fso, SubFolder, RootPath
- End With
- End If
-
-
- CreateFolder Fso, SubFolder, RootPath
- Next SubFolder
- End Function
- Function CopyFileTFolder(Fso As FileSystemObject, oFolder As Folder, RootPath As String)
- Dim oFile As File, oPath As String
- For Each oFile In oFolder.Files
- oPath = Replace(oFile.Path, ThisWorkbook.Path, Path)
- Debug.Print oFile.Path, oPath
- If Fso.FileExists(oPath) = False Then
- Fso.CopyFile oFile, oPath
- End If
- Next oFile
- With oFolder
- Debug.Print .Name, .Files.Count, .Files.Count, Format(Time - T, "h:mm:ss")
- End With
- End Function
复制代码
|
|