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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to rename a file with adding current date?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i want to rename my log file with a backup date,like log_03122002.log,how get it?
 
I had to do a similar thing, Only I had to take the date a file was last modified.

You should be able to use the date function to get the current system date.

You can not rename you will have to copy and delete the original.

A sample of my code is shown below.

Hope it helps.

day = Left(objItem.DateLastModified,2)
mth = Mid(objItem.DateLastModified,4,2)
year = Mid(objItem.DateLastModified,7,2)
hour = Mid(objItem.DateLastModified,10,2)
minute = Mid(objItem.DateLastModified,13,2)
sec = Mid(objItem.DateLastModified,16,2)
If fso.FileExists(destname & day & mth & year & hour & minute & sec & ".CSV") then
msgbox objItem.name & " Already exists in destination directory, Please call the helpdesk"
Else
fso.CopyFile dirname & objitem.Name ,destname & year & mth & day & hour & minute & sec & ".CSV"
End If

If you want to see all of the program, let me know.

Regards
Steve Friday
 
If I presume that the file you want to rename is c:\logs\log.log, you can rename it as follows

Dim myDay, myMonth, myYear
if Day(date) < 10 then
myDay = &quot;0&quot; & Day(date)
else
myDay = Day(Date)
end if

if Month(date) < 10 then
myMonth = &quot;0&quot; & Month(date)
else
myMonth = Month(Date)
end if

myYear = Year(Date)

Dim fso
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
fso.MoveFile &quot;c:\logs\log.log&quot;, &quot;c:\logs\log_&quot; & myMonth & myDay & myYear & &quot;.log&quot;
set fso = nothing

Hope that helps Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top