Devashri B.
Devashri B.

Reputation: 2703

VBScript Copy same file with adding second in Timestamp

I want to copy same file 10000 times with timestamp change using VB Script. Original File name is MyFile.txt. So it will be copied like MyFile_20100131010000.txt. Second time file should be copied with name MyFile_20100131010001.txt.And so on like MyFile_20100131021003.txt. I am using below code snippet. But not sure how to convert DateAdd("s",intCount,"31-Jan-10 08:50:00") to timestamp. e.g

For intCount = 1 to 10000   
     strDate = DateAdd("s",intCount,"31-Jan-10 08:50:00") 
     strNewName = objFSO.GetBaseName(objSourceFile) & "_" & strDate & "." & objFSO.GetExtensionName(objSourceFile)
    'CopyFile(strNewName)
Next 

Please advise.

Upvotes: 0

Views: 598

Answers (1)

tobriand
tobriand

Reputation: 1167

Ok, this is slightly easier in VBA, as intimated in my comment, but it's not that tricky in VBScript either.

The function you're after is the DatePart one. It has a bunch of arguments that you're using that can be found here.

To generate a year-month-day-hour-minute-second timestamp using it, you basically concatenate a lot of those arguments together. Just in case there's a tick between seconds between function executions, it's worth assigning dtNow beforehand:

Dim dtNow
Dim i
Dim strDatePart

For i = 0 to 10000
    dtNow = DateAdd("s",i,"31-Jan-10 08:50:00")
    strDatePart = DatePart("yyyy", dtNow) & DatePart("m", dtNow) & DatePart("d", dtNow) & DatePart("h", dtNow) & DatePart( "n", dtNow) & DatePart("s", dtNow)
    '' Save your file here
Next

Upvotes: 1

Related Questions