简体   繁体   中英

Copy and Rename File VBScript

I need to move a file with a name based off of a date to another folder.

The file structure is:
Source: \\\\network_location\\folder\\Filename_09-11-2012.txt

Destination: C:\\Dump\\Filename.txt

The source file is always 1 day behind. I am looking to rename the file while copying it.
The code I am trying to use is:

Sub Copy_And_Rename()
    Name "\\network_location\folder\Filename_"+Month(Now())+"-"+Day(Now()-1)+"-"+Year(Now())+".txt" As "C:\Dump\Filename.txt"
End Sub

You can copy and rename a file with the FileSystemObject like this:

Set objFSO = CreateObject("Scripting.FileSystemObject")
' First parameter: original location\file
' Second parameter: new location\file
objFSO.CopyFile "C:\Test\folder1\name1.txt", "C:\Test\folder2\name2.txt"

Code to copy and rename file

sourceFilePath = "C:\filePath\source.xlsx"
destinationFilePath = "C:\filePath\destination.xlsx"

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile sourceFilePath, destinationFilePath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM