Skip to main content

VB script to copy folders to a USB/Drive

Today I had to find a solution for a user to backup/copy his folders to a USB drive. Instead of using backup utilities, I wanted to try my luck in VB script. As usual Google'd and found hundreds of scripts. Took codes from several of them and compiled one which will copy folders from one drive to another with prompting the user that it is copying. The script creates an archive folder if it doesn't exist. Create a folder with the date and puts data inside that. So in case one of your backup is corrupted you will have date wise copies of your data.

The code is as below.

=================Code start=====================

Dim objFSO, objWshell, oIE, oIEDoc

set objWshell = Wscript.CreateObject("Wscript.Shell")
Set oIE = Wscript.CreateObject("InternetExplorer.Application")
oIE.Navigate "about:blank"
do while oIE.busy : wscript.sleep 10 : loop
Set oIEDoc = oIE.Document

oIE.AddressBar = False
oIE.StatusBar = False
oIE.ToolBar = False
oIE.Document.Body.Scroll = "no"
oIE.document.title = "... - Processing files"
oIE.height=100
oIE.width=200
oIE.Resizable = False
oIE.Visible = True

sMsg= "<center>Files are being copied.<br>Please wait...</center>"
oIEDoc.Body.Innerhtml= sMsg

sourceDir1 = "path\to\folder"
sourceDir2 = "path\to\folder"
sourceDir3 = "path\to\folder"
destinationDir = "USBDriveletter:\archive"

Set objFSO = CreateObject("Scripting.FileSystemObject")
IF objFSO.FolderExists(destinationDir) = FALSE THEN
objFSO.CreateFolder destinationDir
wscript.echo "Archive folder created"
ELSE
wscript.echo "Archive folder already exists"
END IF

const OverwriteExisting = True

strDirectory = destinationDir & "\" & replace(date,"/","_")
Set fso = CreateObject("Scripting.FileSystemObject")

if not fso.FolderExists(strDirectory) then
   Set objFolder = fso.CreateFolder(strDirectory)
end if
   fso.CopyFolder sourceDir1 , strDirectory & "\", OverwriteExisting
   fso.CopyFolder sourceDir2 , strDirectory & "\", OverwriteExisting
   fso.CopyFolder sourceDir3 , strDirectory & "\", OverwriteExisting

Set oIEDoc = Nothing
oIE.Quit
Set oIE = Nothing

Set objFSO = Nothing
Set objWshell = Nothing
Set WshShell = Nothing

MsgBox "Process completed successfully", 64 + 262144, "Process complete"
=================Code end=====================

Thanks to all who have published their code publicly. I am carrying it forward. Feel free to use and a comment if you feel it is good.

Comments

Popular posts from this blog

How to Configure Samba to Share a Folder with Two Users on Ubuntu (with Read/Write and Read-Only Permissions)

Samba is a file sharing software that allows you to share files between Linux and Windows computers. It is a popular choice for home users and businesses alike. In this article, we will show you how to configure Samba to share a folder with two users, one with read/write permissions and one with only read permissions, on Ubuntu. Prerequisites Before you begin, you will need the following: A Linux computer running Ubuntu Two user accounts A shared folder Steps Install Samba. sudo apt install samba Create the shared folder. sudo mkdir /shared Configure Samba's global options. Open the Samba configuration file /etc/samba/smb.conf in a text editor. Add the following lines to the [global] section: security = user passdb backend = tdbsam This will set the security mode to user , which means that users will be authenticated using their local Linux accounts. The passdb backend option specifies the database that Samba will use to store user passwords. In this case, we are using the tdbsa

GM Diet for the second time

I have yesterday started following GM diet for the second time. First was last month almost in the mid. I lost 2kgs. If you want to follow the diet scheme please find the details below. This is an extract of 'weight loss diet' circulated by many companies and banks among its employees in USA & India. This has proved to be the very effective program for weight loss. Hope this will be of much use to all those who are conscious of their weight and health. WEIGHT LOSS DIET for 7 days (Tested by corporates) This program was developed in conjunction with the grant from the US Department of Agriculture and the Food and Drug Administration. It was field tested at the Johns Hopkins Research Centre and was approved for distribution by the Board of Directors of General Motors Corporation at a general meeting on August 15, 1995. This Program is designed for a target weight loss of 5 - 6 Kgs per week. But it all depened on your body structure and the way you follow it. It will also impr

Create Great looking diagrams - Gliffy.com

I was looking for an online diagram creating tool. Came across Gliffy.com where I could create actually great looking diagrams without much of learning curve. The tool is 1. Very easy to use 2. Has drag and drop of elements to your diagram 3. Collaboration (which I have not tested). 4. Works from anywhere on a browser with Internet connection (I used it in Google Chrome on Linux Mint 10) When you click on the "Try it now" a new screen will open as below. You can either create a blank page to create a diagram from scratch or select from a bunch of samples and work on them to create one for your requirement. There are options to export the diagrams you created to SVG, JPEG, PNG and XML format once you register for free on the website. Once you register you can save the diagrams that you created in the site itself and retrieve it at a later time by logging into the website. I made three diagrams and it was real easy and simple. The site has two kind of pa