## Create A Folder In VBScript With Todays Date And Backup Your Work To It

Category VBScript Sub Category Backing Up
This script is useful when creating backup routines and needing to create a new unique folder. By using the current system date the folder will be different each time, assuming it is not run more than once a day. This would be typical for instance when doing nightly backups of your development work.
Copy Code
'assumes c:\in exists and has all the files and recursive folders you want to copy
'assumes c:\out exists

sourceDir = "c:\in"
destinationDir = "c:\out"
const OverwriteExisting = True
' I used the replace function to change the date format from 8/22/2008 to 8_22_2008
' because the / is not allowed in a file or folder name
strDirectory = destinationDir & "\" & replace(date,"/","_")
Set fso = CreateObject("Scripting.FileSystemObject")
' The script will error out if it tries to create a directory that already exist
' so it is better to check for it first and only attempt to create it if it does
' not exist.
if not fso.FolderExists(strDirectory) then
' If it gets here then the folder for the current date does not yet exist and
' therefore is created.
Set objFolder = fso.CreateFolder(strDirectory)
end if
' This copies the folder and overwrites them if they exist.
fso.CopyFolder sourceDir , strDirectory & "\", OverwriteExisting
' If you entend to automate this script you should remove or rem out this next line.
wscript.echo "Done"

Share the love

## Choose a SubCategory

 Backing Up General