Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming a file with VB Script

Status
Not open for further replies.

ri

Programmer
Nov 2, 2000
12
0
0
GB
The follwing code copies a file from one location to another. What I need to do is once copied over to rename it as another program is looking to pick up this file but must only be able to when it is fully copied over and not partially so. Therefore once its been copied over I need to perform this operation. Any ideas?

'--------------------------------------------------------------------------------------------
' Declare constants
'--------------------------------------------------------------------------------------------

Const DATA_PATH = "D:\Gblon1so4\Datatrue\"
Const MOVE_PATH = "D:\Gblon1so6\Shared\WebReportData\NewData.csv"

'--------------------------------------------------------------------------------------------
' Declare the objects
'--------------------------------------------------------------------------------------------

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = FSO.GetFolder(DATA_PATH)
Set colFiles = objFolder.Files

'--------------------------------------------------------------------------------------------
' Search for the correct file
'--------------------------------------------------------------------------------------------

For Each FileObj In colFiles

Dim File_String

File_String = Right(FileObj, 5)

If File_String = "X.csv" Then

Copy_File(FileObj.Name)

End If
Next

'--------------------------------------------------------------------------------------------
' Move the file and rename it. Delete the initial file
'--------------------------------------------------------------------------------------------

Sub Copy_File(filename)

FSO.CopyFile DATA_PATH & filename, MOVE_PATH
FSO.DeleteFile DATA_PATH & filename

End Sub

 
I think the easiest would be to use
FileObj.Move MOVE_PATH & NewName

Good luck,
Peter
 
Unfortunately, FSO does not have a "renameFile" method. However, you can rename a file using FSO's movefile method. Simply enter the old name and the new name as parameters, for example:

<%
Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
fso.moveFile &quot;c:\boot.ini&quot;, &quot;c:\boot.old&quot;
Set fso = Nothing
%>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top