|
- Set SHX = Worksheets("Sheet1")
- PATH原始 = ThisWorkbook.Path & "\原始文件"
- PATH结果 = ThisWorkbook.Path & "\结果"
- Set FSO = CreateObject("Scripting.FileSystemObject")
- If FSO.FolderExists(PATH结果) = True Then
- FSO.GetFolder(PATH结果).Delete '//删除文件夹
- End If
- MkDir PATH结果 '//创建文件夹
-
- INTX = 0
- FileArr = FileAllArr(ThisWorkbook.Path, "*.*", ThisWorkbook.Name, True, False) '//含子文件夹;文件路径
- If FileArr(0) <> "" Then
- Rem 原始文件 文件清单
- For I = 0 To UBound(FileArr)
- StrNAME = GetPathFromFileName(FileArr(I), True) '//显示文件名
- For IROW = 1 To SHX.Range("A100").End(3).Row
- Rem 找到对应文件夹名
- If InStr(StrNAME, SHX.Cells(IROW, 1).Value) > 0 Then
- Path = PATH结果 & "" & SHX.Cells(IROW, 1).Value
- If FSO.FolderExists(Path) = False Then
- MkDir Path '//创建文件夹
- End If
- Rem 剪切文件过去
- OldName = FileArr(I)
- NewName = Path & "" & StrNAME
- If FSO.FileExists(NewName) = True Then
- Rem 如果重名,则前面加上序号
- NewName = Path & "" & I & "_" & StrNAME
- End If
-
- Name OldName As NewName
- INTX = INTX + 1
- Exit For
- End If
- Next
-
- Next
- End If
复制代码 |
|