web analytics
Copying and Renaming file in VBScript Options
davegate
Posted: Thursday, January 21, 2016 10:52:19 AM

Rank:Advanced Member
Groups: Member
Joined: 12/14/2015
Posts: 164
Points: 801

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.

Sponsor
Posted: Thursday, January 21, 2016 10:52:19 AM
 
Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.