web analytics

Copying and Renaming file in VBScript

Options

davegate 143 - 921
@2016-01-21 10:52:19

In VBScript, you can use FileSystemObject.CopyFile method to copy and/or rename a file.

Dim fso      ' FileSystemObject object.
Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists("c:\temp\anyfile.html") Then
   fso.CopyFile "c:\temp\anyfile.html", "c:\destfolder\newfile.html",true
End If

This method lets us copy one or more files from one location ( the source) to another (destination). Wildcards can be used within the source string, providing it is the last component in the path, to enable the copying of multiple files, but cannot be used in the destination string.

The third parameter is a Boolean. True allows the overwriting of existing files in the destination, providing that the permissions on the destination allow it.

It is recommended that you use the FileExists method when copying or moving a file - if a source file doesn't exist you'll get an error.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com