Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

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

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
0
Balack
Asked:
Balack
  • 3
  • 2
1 Solution
 
CitizenRonCommented:
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.
0
 
CitizenRonCommented:
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.
0
 
BalackAuthor Commented:
Hi CitizenRon:

Does this script only allow up to 3 backup copies?
0
 
CitizenRonCommented:
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.
0
 
BalackAuthor Commented:
good
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now