VBA- 提取指定文件夹下所有文件到指定目录

Sub copyFiles(Path As String, afterPath)

'Path:原文件夹路径;afterPath:目标文件夹路径

Dim Spath As String

'设置文件对象

Set fs = CreateObject("Scripting.FileSystemObject")

'拿到文件夹名

Spath = Dir(Path, vbDirectory)

'判断文件夹

Do While Len(Spath)

'判断文件夹不为当前文件夹和其父文件夹

If Spath <> "." And Spath <> ".." Then

'复制文件夹下的所有文件

fs.CopyFolder Path, afterPath?

'下一个文件夹

Spath = Dir()

End If

Loop

End Sub

Copyright © 2088 下届世界杯_看世界杯 - rcysbj.com All Rights Reserved.
友情链接