Hi all,
My next endeavor is to try and move a subdirectory/(folder) with all its contents to another parent folder (subfolder) on the same drive.
Example to move: MyCityA to another State.
Before Move:
C:/MyCountry/MyStateA/MyCityA
C:/MyCountry/YourStateB/
After Move:
C:/MyCountry/MyStateA/
C:/MyCountry/YourStateB/MyCityA
I've seen plenty of code and have been help with moving files, but have not had any luck
finding any examples on moving a directory.
MvDir
Here's something I've not tested, but hopefully will be the start of what I need.
Sub Move_Folder()
Dim objFSO As FileSystemObject, objFolder As Folder, PathExists As Boolean
Dim objFile As File, strSourceFolder As String, strDestFolder As String
Dim x, Counter As Integer, Overwrite As String
Application.ScreenUpdating = False 'turn screenupdating off
Application.EnableEvents = False 'turn events off
'identify path names below:
strSourceFolder = "C:\MyCountry\MyState\MyCityA" 'Source path
strDestFolder = "C:\MyCountry\YourState\"
'below will verify that the specified destination path exists, or it will create it:
On Error Resume Next
x = GetAttr(strDestFolder) And 0
If Err = 0 Then 'if there is no error, continue below
PathExists = True 'if there is no error, set flag to TRUE
Overwrite = MsgBox("The folder may contain duplicate files," & vbNewLine & _
"Do you wish to overwrite existing files with same name?", vbYesNo, "Alert!")
'message to alert that you may overwrite files of the same name since folder exists
If Overwrite <> vbYes Then Exit Sub 'if the user clicks YES, then exit the routine..
Else: 'if path does NOT exist, do the next steps
PathExists = False 'set flag at false
If PathExists = False Then MvDir (strDestFolder) 'If path does not exist, make a new one
End If 'end the conditional testing
Bookmarks