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
To RENAME an Excel file that is stored on your computer, you need to use the “NAME” statement. In this statement, you need to define the old file name and the new name that you want to apply. But there's one thing that you need to remember the file must be closed.
The following scripts demonstrate how to copy a file from one local folder to another. In the first step, the script creates a File System Object. The CopyFile method, a file system object method, performs the file copy operation. The CopyFile method takes two parameters, the source file and the destination.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With