Results 1 to 13 of 13

Thread: Moving folders and sub-folders ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736

    Question

    I have tried using the FileSystemObject to move a folder that contains text files and up to 3 levels of sub-folders, but with no luck. I need to move the folder and everything in it from one server to another.

    Does anyone have a working example of doing this ?

    Or is there a better way ?

    Thanks.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You should be able to use the MoveFolder Method of the FileSystemObject, but in some cases it make give you a Permission Denied Error when moving to another volume (or server), if this is the case use a 2 pass process, i.e
    Code:
    Private Sub Command1_Click()
        Dim oFSO As Object
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        Call oFSO.CopyFolder("C:\Test", "D:\Test")
        Call oFSO.DeleteFolder("C:\Test", True)
        Set oFSO = Nothing
    End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Thanks Aaron.

    That was exactly what was happening, and your solution works great. You saved me several more hours of frustration.

  4. #4
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: Moving folders and sub-folders ?

    is copying slower than moving??

    p.s. sorry to bring an old thread... but it's better to use this one rather than create a new one ...isn't it?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Moving folders and sub-folders ?

    Quote Originally Posted by lplover2k
    is copying slower than moving??

    p.s. sorry to bring an old thread... but it's better to use this one rather than create a new one ...isn't it?
    Moving is copying, then going back and deleting.

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Moving folders and sub-folders ?

    i was under the impression that moving just changes where the file is indexed in the filesystem - no actual data is moved, and it's certainly not copied and killed (unless it's across drives, I guess) - thus Moving is faster than Copying

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Moving folders and sub-folders ?

    Quote Originally Posted by bushmobile
    i was under the impression that moving just changes where the file is indexed in the filesystem - no actual data is moved, and it's certainly not copied and killed (unless it's across drives, I guess) - thus Moving is faster than Copying
    From an OS standpoint you are correct.

    However, programmatically, from VB, you would have to use "FileCopy" and then "Kill" to perform a "Move"

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Moving folders and sub-folders ?

    Quote Originally Posted by Hack
    From an OS standpoint you are correct.

    However, programmatically, from VB, you would have to use "FileCopy" and then "Kill" to perform a "Move"
    VB Code:
    1. Name "C:\blah.txt" As "C:\text\blah.txt"

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Moving folders and sub-folders ?

    Quote Originally Posted by bushmobile
    VB Code:
    1. Name "C:\blah.txt" As "C:\text\blah.txt"
    Good point....for some reason my aged brain never associated this type of code with anything but file renaming.

    I think I'll go home and take a nap.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Moving folders and sub-folders ?

    Quote Originally Posted by lplover2k
    is copying slower than moving??

    p.s. sorry to bring an old thread... but it's better to use this one rather than create a new one ...isn't it?
    Actually, it would be best to create a new thread and post a link to the thread you are referencing.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: Moving folders and sub-folders ?

    oh ok... will do that next time... why is bringing old threads bad...???

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Moving folders and sub-folders ?

    Well without going too far off topic, because it also sends out notifications to ever member that is subscribed to the thread for one. Another would be that in a way its thread hijacking - taking over someone else's thread topic. . And still, members will see the initial question and have to be bothered with reading the entire thread to find that it was solved and some addition/off topic question was asked when it would save them time to just have a new thread and read a single post.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Moving folders and sub-folders ?

    another reason: if you jump on a RESOLVED thread, then most people aren't going to bother looking at it.

Posting Permissions

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



Click Here to Expand Forum to Full Width