How to create a vbs script to copy files and folders to mapped drive?

Posted on 2011-04-29
Last Modified: 2012-05-11
This is a windows 2008 server. I want to create a vbs script file to copy e:\testfolder1, h:\testfolder2, and h:\testfolder3, all subfolders and files over to the mapped drive > Q:. How should I create the vbs script to achieve the above purpose? Secondly, I will use task scheduler to automate the process, will it be any problem? Pls see the command for my file copying:

    xcopy e:\testfolder1\* q:\testfolder1\%date:~0,3%\* /Y /Q /S
Question by:Balack
    LVL 7

    Expert Comment

    The script part is pretty easy:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strFolderDate = Year(Now) & "-" & Right("0" & Month(Now),2) & "-" & Right("0" & Day(Now),2)
    objFSO.CopyFolder "e:\testfolder1","q:\testfolder1\" & strFolderDate, 1
    objFSO.CopyFolder "h:\testfolder2","q:\testfolder2\" & strFolderDate, 1
    objFSO.CopyFolder "h:\testfolder3","q:\testfolder3\" & strFolderDate, 1

    Open in new window

    I made the date show up as YYYY-MM-DD, for example "2011-08-24".

    The task scheduler part is a little trickier.  The task scheduler in Windows 2008 (taskschd.msc) is a lot more robust and complicated but there's a couple basic options you'll want to make sure you use when you create the task using "Create Task..." not "Create Basic Task...":
    Choose a user account that has at least read access to the source folders and full access to the destination folder
    Enable "Run whether user is logged on or not"
    Enable "Run with highest privileges"
    They're all on the first tab ("General") of the "Create Task" window.
    LVL 7

    Expert Comment

    I always forget this part...

    Mapped network drives are not usually available in a scheduled task.  You can map the drives inside the script but it's easier if you just use UNC paths for the sources and destinations in the script.

    Author Comment

    Hi CitizenRon:

    Does this script only allow up to 3 backup copies?
    LVL 7

    Accepted Solution

    This script?  Yes, since that's what you asked for.  Three specific folders to be copied to a mapped network drive.  

    All you'd have to do is add more objFSO.CopyFolder lines with additional source and destinations to copy more folders.  Again though, the script won't work in a scheduled task unless we map the drive within the script or change the source/destination paths to UNC.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
    A quick step-by-step overview of installing and configuring Carbonite Server Backup.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    21 Experts available now in Live!

    Get 1:1 Help Now