We help IT Professionals succeed at work.

VBScript File Copy and Rename

I am working on a script to copy and rename a file, i am getting an error on the last line.. mismatch..'FileCopy', I am not sure what i have wrong
Dim Location
Dim BackupLocation
Dim FileName
Dim BacupFileName 
DIM strComputer
DIM PCName                                       

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_ComputerSystem",,48)<wbr ></wbr> 
For Each objItem In colItems 
    PCName = objItem.Name
Next


Location = "C:\Program Files\ProgramFolder\SubFolder\SubSubFolder"
BackupLocation =  "y:\SOuser"
FileName="users.xml"
BacupFileName = PCName & ".xml"

FileCopy Location & "\" & FileName, BackupLocation & "\" & BacupFileName

Open in new window

Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Change the FileCopy line to this:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile Location & "\" & FileName, BackupLocation & "\" & BacupFileName

Open in new window

~bp

Author

Commented:
This worked perfectly, Thank You
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Great, glad that's all it was. thanks for the feedback.

~bp

Explore More ContentExplore courses, solutions, and other research materials related to this topic.