I'm trying to create a vb script which copies files to a backup folder every x minutes.
I can create a backup folder if it doesn't exist. I can copy the files into the "backup" folder. I can create sub folders within the "backup" folder that are named by todays date - this also works.
The problem I have is getting the full path of the destination folder to copy the files into. Basicallty I'm struggling to use the date variable within a folder structure.
Here's my code, where am I going wrong? It'something to do with the NewFolder variable.
'create the folder if exists
set fso = CreateObject("Scripting.FileSystemObject")
dim NewFolder, parent, path, todaydate
TodayDate = FormatDateTime(Date, 1)
path = "C:\"
NewFolder = "Backup" & "\" & todaydate
if not fso.FolderExists(path & "\" & NewFolder) then
fso.CreateFolder(path & "\" & NewFolder)
'Copy the File
Dim fso 'to become a FileSystemObject
Dim fol 'to become a folder object
Dim fil 'to become a file object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("C:\documents and settings\all users\documents")
For Each fil In fol.Files
fil.Copy newfolder & fil.name