Results 1 to 3 of 3

Move a Subfolder with Contents

Threaded View

bdb1974 Move a Subfolder with Contents 06-02-2010, 04:54 PM
dominicb Re: Move a Subfolder with... 06-02-2010, 06:06 PM
bdb1974 Re: Move a Subfolder with... 06-03-2010, 04:51 PM
  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Move a Subfolder with Contents

    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
    Last edited by bdb1974; 06-03-2010 at 04:51 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1