Copy and rename VBScript file

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

File structure:

Source: \ network_location \ folder \ Filename_09-11-2012.txt Purpose: C: \ Dump \ Filename.txt

The source file is always 1 day. I want to rename the file when copying it.

The code I'm 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 

thanks

+7
source share
1 answer

You can copy and rename a file using FileSystemObject as follows:

 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" 
+12
source

All Articles