File Copy/Move using vbs

LostInWindows
LostInWindows used Ask the Experts™
on
I am trying to do some regular file management using vbs.
I am not very proficient in vb script but I am missing something here.

I have a script that needs to accomplish this:
Using Existing Directory d:\Backups
Create a sub folder called YYDDMM
Copy a file called D:\QuickBooks\Daily\*.QBB to D:\Backups\YYDDMM\

I can do everything except the last line. When I use a msgbox it shows that my destination path is blank.

Can you advise what is missing or wrong in this script?
It continuously fails on line 58 saying
"Invalid attempt to call Exec without a command".
QBBackupFileManagement.vbs
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Try this:

' Description:
' Tool for handling backingups of files in QuickBooks
'
' Will generate directory names with the following style: YYYYMMDD
' E.g.: 20070228
' QuickBooks is scripted to automatically 

Option Explicit
'==========================================================================
' Before we get too far into this whole process let's make sure that the backup Path actually exists
'==========================================================================

Const BackupPath = "D:\Backups\QuickBooks\Backup\"
Const sSourceFile = "D:\Backups\QuickBooks\Daily\*.QBB"
Const OverwriteExisting = True

Dim fso, Folder, filedate, f, file, filesys, FolderCollection, iDaysOld, iReturn
Dim sBackupPrefix, objshell, strcmd

set filesys = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")

'Wscript.Echo Now & " - backup script started."

if Not fso.FolderExists(BackupPath) then
   WScript.Echo "The folder " & BackupPath & " does not exist!"
   WScript.Quit
end if

'==========================================================================
'This portion of the script will delete all backups in the folder that are more than 7 days old
'==========================================================================

'Wscript.Echo Now & " - Deleting old folders..."

DeleteBackup("D:\Backups\QuickBooks\Backup")   ' Call the Delete Subroutine

'==========================================================================
'Now we copy the QuickBooks files
'==========================================================================

'Set folder = fso.GetFolder(BackupPath)
filedate = NOW
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)
msgbox ssourcefile & chr(20) & sbackupprefix

Set folder = filesys.CreateFolder(sBackupPrefix)

'Wscript.Echo "Backup folder will be: [" & sBackupPrefix & "]"

Set objShell = CreateObject("WScript.Shell")

fso.CopyFile (sSourceFile, sBackupPrefix)

Set objshell = nothing

'Wscript.Echo Now & " - script ended."

'============================================================================
Sub DeleteBackup(ParentFolder)
Dim fs, f, f1, s, sf, d
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(ParentFolder)
Set sf = f.SubFolders
For Each f1 in sf
      s = f1.DateCreated
      d = DateDiff("d", s, Now)
      If d > 7 Then
           'Wscript.Echo "Deleting folder: [" & f1.Path & "]"
           f1.delete(True)
      End If
Next

End Sub
'=============================================================================

Open in new window

~bp

Author

Commented:
Thanks,
Line 56 which says:    fso.CopyFile (sSourceFile, sBackupPrefix)
I get an error message saying "Cannot use parenthesis when calling a sub"
Test your restores, not your backups...
Top Expert 2016
Commented:
Okay, change that to:

fso.CopyFile sSourceFile, sBackupPrefix

~bp

Author

Commented:
Thank you, I really appreciate it!
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Welcome, thanks for the feedback.

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial