Renaming file with create date VBS

Hewlett-packard / P5700
March 5, 2009 at 11:03:24
Specs: Windows XP, intel 2.4
I am trying to append the create date to a txt file as backup_ddmmyyhhmmss. But instead I get yyyymmddhhmmss.log. Can someone please help me with the format. thanks

this is what I have so far:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='c:\TEST'} Where " _
& "ResultClass = CIM_DataFile")

For Each objFile In FileList
strDate = Left(objFile.CreationDate, 14)
strNewName = objFile.Drive & objFile.Path & _
strDate & "." & "log"
strNameCheck = Replace(strNewName, "\", "\\")

i = 1
Do While True
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile Where Name = '" & strNameCheck & "'")
If colFiles.Count = 0 Then
errResult = objFile.Rename(strNewName)
Exit Do
Else
i = i + 1
strNewName = objFile.Drive & objFile.Path & _
strDate & "_" & i & "." & "log"
strNameCheck = Replace(strNewName, "\", "\\")
End If
Loop
Next


See More: Renaming file with create date VBS

Report •


#1
March 14, 2009 at 02:40:30
one way to do it is this:
strDate = now
d = day(strDate)*10000 + month(strDate)*100 + right(year(strDate),2)
t = hour(strDate)*10000 + minute(strDate)*100 + second(strDate)
wsh.echo d & t

set strDate variable to the file creation date/time


Report •
Related Solutions


Ask Question