7,763
社区成员
发帖
与我相关
我的任务
分享
Function FilesTree(sPath)
'遍历一个文件夹下的所有文件夹文件夹
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder(sPath)
Set oSubFolders = oFolder.SubFolders
sMoveToPath = oFolder.ParentFolder.Path
sAddName = oFolder.Name
sAddName = "-[" & sAddName & "]"
if oSubFolders.count>0 then
For Each oSubFolder In oSubFolders
FilesTree(oSubFolder)'递归
if oSubFolder.size<50 then
oSubFolder.delete
end if
Next
end if
Set oFiles = oFolder.Files
For Each oFile In oFiles
sNewName = ofile.name
sNewName = mid(sNewName,1,instrrev(sNewName,".")-1) & sAddName & mid(sNewName,instrrev(sNewName,"."))
ofile.name = sNewName
'就是这里有问题
'msgbox sMoveToPath& "\n"& ofile.path'从msgbox看不存在重名
oFso.movefile ofile.path,sMoveToPath
'用这个移动也不行
'ofile.Move(sMoveToPath)
Next
Set oFolder = Nothing
Set oFso = Nothing
End Function
set oSubFolders = CreateObject("Scripting.FileSystemObject").GetFolder(".").SubFolders
For Each oSubFolder In oSubFolders
FilesTree(oSubFolder.path)'递归
Next
Set oSubFolders = Nothing