I would like a macro to move all files in C:\downloads as well as the sub-folders to C:\Old Downloads
If a duplicate file exists, in C:\old downloads, it can be overwritten
It would be be appreciated if someone could kindly assist
I would like a macro to move all files in C:\downloads as well as the sub-folders to C:\Old Downloads
If a duplicate file exists, in C:\old downloads, it can be overwritten
It would be be appreciated if someone could kindly assist
Re: Macro to move all files including Sub-Folders
Hi,
Would recommend to take a look at Ron's site ... http://www.rondebruin.nl/win/s3/win026.htm
HTH
Re: Macro to move all files including Sub-Folders
Thanks for the reply
I have adapted the code as folows, but as C:\old Downloads already exists, no files and sub-folders are moved
It would be appreciated if you could kindly assist me
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "C:\downloads" '<< Change
ToPath = "C:\Old downloads" '<< Change
'Note: It is not possible to use a folder that exist in ToPath
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
If FSO.FolderExists(ToPath) = True Then
MsgBox ToPath & " exist, not possible to move to a existing folder"
Exit Sub
End If
FSO.MoveFolder Source:=FromPath, Destination:=ToPath
MsgBox "The folder is moved from " & FromPath & " to " & ToPath
End Sub
Display More
Re: Macro to move all files including Sub-Folders
Here's another one to try..
Private Sub CommandButton1_Click()
Dim z, strSource As String, strDest As String, i As Long
'Set Source and Destination Folder paths
strSource = "F:\Old\": strDest = "F:\New\" ' change to suit
'Put all Folders in Source folder into an array
z = Split(CreateObject("wscript.shell").exec("cmd /c Dir """ & strSource & "*.*"" /s /b /o:n").stdout.readall, vbCrLf)
'Loop though the Array
For i = LBound(z) To UBound(z) - 1
'Move the files from each folder to the Destination Folder.. overwriting existing ones (16)..
CreateObject("shell.application").Namespace((strDest)).MoveHere (z(i)), 16
Next i
End Sub
Display More
For reference... thanks to:
http://www.snb-vba.eu/VBA_Bestanden_en.html#L_85
Re: Macro to move all files including Sub-Folders
Thanks for the help much appreciated
Don’t have an account yet? Register yourself now and be a part of our community!