|
Dim fso As Object '模块级变量
Dim DestinationPath As String
'主程序
Sub main()
Set fso = CreateObject("scripting.filesystemobject")
DestinationPath = "D:\123" '指定目标路径
Call Recursion("D:\BaiduMusic") '指定源路径
Shell "explorer " & DestinationPath & "\", vbNormalFocus
End Sub
'递归程序
Sub Recursion(myPath As String)
Dim myFolder As Object, mySubFolder As Object, myFile As Object
Set myFolder = fso.getfolder(myPath)
'遍历文件夹
For Each mySubFolder In myFolder.SubFolders
Recursion mySubFolder.Path
Next
'遍历文件
For Each myFile In myFolder.Files
'指定操作
If fso.GetExtensionName(myPath & "\" & myFile) = "jpg" Then Call demo(myPath, myFile.Name)
Next
End Sub
'指定操作
Sub demo(myPath As String, myFile As String)
Dim SourceFile, DestinationFile, DestinationPath
SourceFile = myPath & "\" & myFile '指定源文件名
DestinationFile = DestinationPath & "\" & myFile '指定目的文件名
FileCopy SourceFile, DestinationFile '将源文件的内容复制到目的文件中
End Sub
1.rar
(9.73 KB, 下载次数: 15)
|
|