Hello, I found this code in an old post which is almost perfect for what I am trying to achieve.
Unfortunately, I don't understand what the letters in the code refer to... Can the code be modify to exclude subfolders with a specific names?
In my case I want to copy to another location a set of folder which may contain many subfolders and so on. At some point there will be subfolders for each year starting from 2020. What I want to achieve is copy the entire folder structure excluding all years except for the current one.
VBA macro to copy files from one folder (and all it's subfolders, and their subfolders, and their subfolders....) to another folder?
Many thanks!
Unfortunately, I don't understand what the letters in the code refer to... Can the code be modify to exclude subfolders with a specific names?
In my case I want to copy to another location a set of folder which may contain many subfolders and so on. At some point there will be subfolders for each year starting from 2020. What I want to achieve is copy the entire folder structure excluding all years except for the current one.
VBA macro to copy files from one folder (and all it's subfolders, and their subfolders, and their subfolders....) to another folder?
Rich (BB code):
Sub CopyFiles()
Dim sPathSource As String, sPathDest As String, sConsoleCmd As String
sPathSource = "C:\SourceFolder\*.*"
' sPathSource = "C:\SourceFolder\*.pdf"
' sPathSource = "C:\SourceFolder\*.xls?"
sPathDest = "Z:\DestinationFolderTree\SomeFolder\EndpointFolder"
If Not Right(sPathDest, 1) = "\" Then sPathDest = sPathDest & "\"
sConsoleCmd = "cmd.exe /k xcopy " & """" & sPathSource & """" & " " & """" & sPathDest & """" & " /s/i/y/r/k"
Shell sConsoleCmd, 1 ' << change 6 into 1 to see what's going on
End Sub
Many thanks!
Last edited by a moderator: