|
本帖最后由 xiangbaoan 于 2018-8-8 17:15 编辑
'自行测试!操作之前请先删除原先自动创建的文件夹
'老大,I 服了 YOU ,我都快被你搞晕了!
Sub test()
Dim ar, p$, sp$, np$, fld, sfd, f, r%, fso As Object, msg$, n%, k%, m%
Set fso = CreateObject("scripting.filesystemobject")
p = ThisWorkbook.Path & "\"
With Sheet1
.[e1].Resize(888) = ""
ar = .[a1].CurrentRegion.Resize(, 5)
End With
On Error Resume Next
For r = 2 To UBound(ar)
np = p & ar(r, 2)
If Dir(np, vbDirectory) = "" Then fso.createfolder np
np = np & "\"
sp = p & "技术文件\" & ar(r, 1) & "\"
If fso.FolderExists(sp & ar(r, 3)) Then
fso.movefolder sp & ar(r, 3), np & ar(r, 3)
ar(r, 5) = "操作成功!"
Else
n = n + 1
ar(r, 5) = ar(r, 3) & "不存在!"
msg = msg & sp & ar(r, 5) & vbCr
fso.createfolder np & ar(r, 3) & "不存在"
End If
Next
Err.Clear
For Each fld In fso.getfolder(p).subfolders
k = 0
If fld.Name <> "技术文件" Then
For Each sfd In fld.subfolders
For Each f In sfd.Files
If InStr(f.Name, "标签") = 0 Or InStr(f.Name, ".fdf") Then Kill f
Next
If sfd.Files.Count = 0 And InStr(sfd.Name, "不存在") = 0 Then RmDir sfd.Path
Next
k = fld.subfolders.Count
m = 0
For Each sfd In fld.subfolders
If InStr(sfd.Name, "不存在") Then m = m + 1
Next
If m = k Then Name fld.Path As fld.Path & "不含标签"
End If
Next
Set fso = Nothing
Sheet1.[a1].CurrentRegion.Resize(, 5) = ar
If n Then MsgBox msg
End Sub
'真晕了,把pdf打成了fdf
|
|