Automating the creation of input files for load test using VB Script

Loadrunner
We will be needing to create thousands of dummy input text files for our load test. Creating them manually is a long and time consuming process. This can be automated using the below VB script.

Here 
1. We are appending the date and time to the file name to produce unique text files.
2. We have used FOR LOOP to iterate the file creation to the desired count.
3. Also we are writing content to the files to avoid creating empty files, which we can customize with whatever we want to write.

VB Script:

Dim strSafeDate, strSafeTime, strDateTime
Dim i

For i = 0 to 3

strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
strDateTime = strSafeDate & "_" & strSafeTime

Set fso = CreateObject("Scripting.FileSystemObject")
FilePath = "C:\Users\vinoth.srinivasan\Desktop\VB_Scritping\MyText" & "_" & strDateTime & ".txt"
'FilePath= "C:\Users\vinoth.srinivasan\newtextfile" & counter & ".txt"
Set myfile = fso.CreateTextFile(FilePath,2)
myfile.WriteLine "Line1"
myfile.WriteLine "Line2"

myfile.close

set myfile =Nothing
set fso=Nothing

Next

No comments:

Post a Comment