VJ1980
asked on
How to rename a file using VBscript
Hi All,
I have a task of copying previous days log file and rename it to the name of the server to which it belongs and then to generate a statistics page. With help of few friends in this forum i got the script to copy files with yesterday's date using
" dt = DateAdd("d",-1, Date)
yesterday = Right(Year(dt), 2) & Right("0" & Month(dt), 2) & Right("0" & Day(dt), 2)
strfilename = "J:\log\" & "ex" & Right(Year(dt), 2) & Right("0" & Month(dt), 2) & Right("0" & Day(dt), 2) & ".log"
But got stucked with another problem the name of the file is ex110103.log, this file needs to renamed to server1110103.log before generating the report is this possible to do with VB script.
Thanks
VJ
I have a task of copying previous days log file and rename it to the name of the server to which it belongs and then to generate a statistics page. With help of few friends in this forum i got the script to copy files with yesterday's date using
" dt = DateAdd("d",-1, Date)
yesterday = Right(Year(dt), 2) & Right("0" & Month(dt), 2) & Right("0" & Day(dt), 2)
strfilename = "J:\log\" & "ex" & Right(Year(dt), 2) & Right("0" & Month(dt), 2) & Right("0" & Day(dt), 2) & ".log"
But got stucked with another problem the name of the file is ex110103.log, this file needs to renamed to server1110103.log before generating the report is this possible to do with VB script.
Thanks
VJ
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
By the way, is server a variable that hold another name or is it a string ?
ASKER
perfect solution
Demonstration script that uses the FileSystemObject to rename a file. Script must be run on the local computer.
Set objFSO = CreateObject("Scripting.Fi
objFSO.MoveFile "C:\FSO\ScriptLog.txt" , "C:\FSO\BackupLog.txt"
See also: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/#RenameFile.htm
2. create the right filename at once
strfilename = "D:\Inetpub\Wwwroot\SP2010
Replace(strfilename ,"ex","server")