troubleshooting Question

Copy files to a folder which has been created using the date variable

Avatar of tolanc
tolancFlag for United Kingdom of Great Britain and Northern Ireland asked on
Visual Basic ClassicVB Script
7 Comments2 Solutions273 ViewsLast Modified:

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")

sub GetFullPath

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)
  end if
end sub


'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 &

WScript.Sleep 60000
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros