用VBA:将一群PNG图片分到个文件夹,保证文件夹内文件数不超过100
时间: 2024-05-20 16:17:35 浏览: 94
Sub SplitFiles()
Dim folderPath As String
folderPath = "C:\Users\UserName\Desktop\PNG Files\" '修改为你的文件夹路径
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim folder As Object
Set folder = fso.GetFolder(folderPath)
Dim i As Integer
i = 1
Dim subFolder As Object
Set subFolder = fso.CreateFolder(folderPath & "SubFolder_" & i)
For Each file In folder.Files
If fso.GetExtensionName(file.Path) = "png" Then
If subFolder.Files.Count >= 100 Then
i = i + 1
Set subFolder = fso.CreateFolder(folderPath & "SubFolder_" & i)
End If
fso.MoveFile file.Path, subFolder.Path & "\" & file.Name
End If
Next file
MsgBox "操作完成!"
End Sub
阅读全文