我设法让此代码工作。它将所有文件夹/文件和子文件夹及其文件复制到新目标(strTarget)。
如果文件和文件夹已经存在,我还没有像1)那样添加检查和余额。 2)如果源文件是开放的等所以这些增加可能是有用的。
我从Barry的帖子中得到了这段代码,但需要改变它以使其适用于我,所以我认为我会再次分享它。
希望这是有用的,但。 。 。
strPath是源路径,strTarget是目标路径。两个路径应以'\'结尾
注意:需要在“工具/参考”下的“Microsoft脚本运行时”添加FSO才能正常工作。
==================== call ================================
MkDir "DestinationPath"
CopyFiles "SourcePath" & "\", "DestinationPath" & "\"
==================== Copy sub ===========================
Public Sub CopyFiles(ByVal strPath As String, ByVal strTarget As String)
Dim FSO As Object
Dim FileInFromFolder As Object
Dim FolderInFromFolder As Object
Dim Fdate As Long
Dim intSubFolderStartPos As Long
Dim strFolderName As String
Set FSO = CreateObject("scripting.filesystemobject")
'First loop through files
For Each FileInFromFolder In FSO.GetFolder(strPath).Files
Fdate = Int(FileInFromFolder.DateLastModified)
'If Fdate >= Date - 1 Then
FileInFromFolder.Copy strTarget
'end if
Next
'Next loop throug folders
For Each FolderInFromFolder In FSO.GetFolder(strPath).SubFolders
'intSubFolderStartPos = InStr(1, FolderInFromFolder.Path, strPath)
'If intSubFolderStartPos = 1 Then
strFolderName = Right(FolderInFromFolder.Path, Len(FolderInFromFolder.Path) - Len(strPath))
MkDir strTarget & "\" & strFolderName
CopyFiles FolderInFromFolder.Path & "\", strTarget & "\" & strFolderName & "\"
Next 'Folder
End Sub
你检查[这](http://stackoverflow.com/questions/14245712/cycle-through-sub-folders-and-files-in-a-user-specified-root-directory)? – mrbungle 2014-10-01 18:11:56
我有..我不知道如何将它与我已有的。 – gfuller40 2014-10-01 18:26:57