How to copy an entire directory in VB6

Posted on 2014-07-15
Last Modified: 2014-07-16
Hello Experts,

Ok, so I have a quick question I hope.  I am writing a quick application to copy the entire contents of two directories to another directory.  I am programming using VB6, (old school, I know, lol).  Anyway, I am familiar with the standard VB FileCopy command but you can only copy individual files with the command.  Does anyone know of a way I can copy what I need to?  I want to keep the coding as simple as possible.  Thanks in advance!!
Question by:zraptor
    LVL 24

    Accepted Solution

    ' VBScript.
    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.CopyFile "c:\testfolder\*.*", "c:\copttotestfolder\"

    Open in new window

    Just use *.* for all files in a directory.
    LVL 16

    Assisted Solution

    The other option is to utilize the DIR$ command to find all the files in a folder and delete them one-by-one with FileCopy...

    FileName = DIR$("C:\testfolder\*.*")
    while len( FileName )
        FileCopy "C:\testfolder\FileName" "C:\destfolder\FileName"
        FileName = DIR$    'This will get the next file the 1st DIR command found

    Author Closing Comment

    Thank you!!

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    Join & Write a Comment

    A short article about a problem I had getting the GPS LocationListener working.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now