Computing.Net > Forums > Programming > Renaming file with create date VBS

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Renaming file with create date VBS

Reply to Message Icon

Name: hrodriguez411
Date: March 5, 2009 at 11:03:24 Pacific
OS: Windows XP
CPU/Ram: intel 2.4
Product: Hewlett-packard / P5700
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: reno
Date: March 14, 2009 at 02:40:30 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Renaming file with create date VBS

Renaming file with create date www.computing.net/answers/programming/renaming-file-with-create-date/18088.html

Deleting files based on Date www.computing.net/answers/programming/deleting-files-based-on-date/15215.html

renaming files with cdate www.computing.net/answers/programming/renaming-files-with-cdate/16303.html