Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 & tset strDate variable to the file creation date/time

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |