Delete unwanted files and results folders from LoadRunner script folders

It’s a common complaint of IT chaps supporting performance test teams that their script folders are large (especially if you’ve been running scripts with logging enabled for debugging purposes). Lots of files can be deleted before you save or archive your scripts which saves disk space and generally keeps things tidier.

The batch file (tidyup.cmd) attached to this article can help you to tidy up your LoadRunner script folder. It deletes unwanted log files and output files. The following files are deleted.

mdrv.log
mdrv_cmd.txt
options.txt
pre_cci.c
.ci
combined_.c
output.txt
debug.inf
All files with .idx extension
All files with .bak extension
The Result1 folder and it’s contents

 

It is also possible to delete RecordingLog.txt file in the scriptdata folder. If you delete this file, it will not affect the script’s replay. However, you will not be able to see the information about what happened during recording.

 

Batch file – tidyup.cmd Description of action
IF EXIST %temp%blankfile.txt  del %temp%blankfile.txt /q
IF EXIST %temp%FilesDeleted.txt  del %temp%FilesDeleted.txt /q
IF EXIST %temp%FoldersDeleted.txt  del %temp%FoldersDeleted.txt /q
IF EXIST %temp%BadParms.txt  del %temp%BadParms.txt /qtype nul > %temp%blankfile.txt
type nul > %temp%FilesDeleted.txt
type nul > %temp%FoldersDeleted.txt
type nul > %temp%BadParms.txt

del *.idx /s >> %temp%FilesDeleted.txt
del mdrv*.log /s >> %temp%FilesDeleted.txt
del mdrv.txt /s >> %temp%FilesDeleted.txt
del options.txt /s >> %temp%FilesDeleted.txt
del *.ci /s >> %temp%FilesDeleted.txt
del combined_*.c /s >> %temp%FilesDeleted.txt
del output.txt /s >> %temp%FilesDeleted.txt
del debug.inf /s >> %temp%FilesDeleted.txt
del *.bak /s >> %temp%FilesDeleted.txt

for %%d in (h) do (
for /f “delims=” %%a in (‘dir/s/b/ad “%CD%result*”‘) do (
echo “deleted %%a” >> %temp%FoldersDeleted.txt
rd /s /q “%%a”
)
)

rd result1 /s /q

 

findstr /S “:\” *.prm > %temp%BadParms.txt

fc %temp%FilesDeleted.txt %temp%blankfile.txt > nul
if errorlevel 1 “Notepad.exe” “%temp%FilesDeleted.txt”

fc %temp%FoldersDeleted.txt %temp%blankfile.txt > nul
if errorlevel 1 “Notepad.exe” “%temp%FoldersDeleted.txt”

fc %temp%BadParameters.txt %temp%blankfile.txt > nul
if errorlevel 1 “Notepad.exe” “%temp%BadParms.txt”

IF EXIST %temp%blankfile.txt  del %temp%blankfile.txt /q
IF EXIST %temp%FilesDeleted.txt  del %temp%FilesDeleted.txt /q
IF EXIST %temp%BadParms.txt  del %temp%BadParms.txt /q

These lines delete any existing files from previous runs of this batch file.These lines create blank files for later file comparisons.These del functions delete the unwanted LoadRunner files and pipe any output into the %temp%FilesDeleted.txt file.

This “for loop” deletes any sub-folders called result1 and pipes any output into the %temp%FoldersDeleted.txt file.

This deletes the local result1 directory if it exists

This function looks for explicit file paths rather than relative file paths in the .PRM files and writes them to the %temp%BadParameters.txt file.

If FilesDeleted.txt exists, open it in Notepad.exe wo we can see the names of deleted files.

If FoldersDeleted.txt exists, open it in Notepad.exe wo we can see the names of deleted folders.

If BadParameters.txt exists, open it in Notepad.exe wo we can see the names of parameters that don’t use relative file paths (and are less portable).

Finally delete the superfluous temporary files.

 

This batch file can be run either from within a script folder, or from a top-level folder containing multiple LoadRunner scripts. If run in a top level folder it loops through all sub-folders deleting files and results folders as it goes. In both cases, the list of deleted files and folders is displayed using notepad.exe .

Some of my colleagues prefer to have a copy of the tidyup.cmd batch file in all their script folders and some prefer ro run it from the top level folder. If you want a copy of tidyup.cmd in all your sub-folders the copytidy.cmd file can be used to copy the batch file to multiple sub-folders.

Batch file – copytidy.cmd Description of action
for %%d in (h) do (
for /f “delims=” %%a in (‘dir /a:D /b’) do (
copy %%a tidyup.cmd
)
)
For each sub folder identified by the dir /a:D /b command.
Copy the tidyup.cmd command into the folder.

 

 

 

Deleting bad lines of data from multiple parameter files.

When performance testing it is common to find some lines of test data which are no longer valid. They may be user IDs which have expired or simply no longer exist in your test database. Finding and removing these bad lines of test data from parameter files can be time-consuming.

This batch file, prmclean.cmd can be used to remove known bad data from all data files in a data folder.  The batch file does not prompt for folder names and currently relies on the .dat files residing in a folder called LR_TestData.

The batch file can be easily modified to work with any text files.  No additional software is required (e.g. PERL) and this batch file will run on any windows PC.

Batch file Description of action
IF EXIST LR_TestData_old  rd LR_TestData_old /s /q

md LR_TestData_old

 

 

REM Copy all data files to “LR_TestData_old”

for %%d in (h) do (

for /f “delims=” %%a in (‘dir LR_TestData*.dat /b’) do (

copy LR_TestData%%a LR_TestData_old

)

)

 

REM Loop through the .dat files writing contents without bad data into new .tmp files

for %%d in (h) do (

for /f “delims=” %%a in (‘dir LR_TestData*.dat /b’) do (

findstr /V /G:bad.txt LR_TestData%%a > LR_TestData%%a.tmp

)

)

 

 

 

REM Delete old .dat files

del LR_TestData*.dat

 

REM Rename .tmp files into .dat files

ren LR_TestData*.tmp *.

These lines create a folder to keep a copy of the original data files.

 

 

This loop copies all the current data files into a folder called LR_TestData_old.

 

This loop copies data into new data files (with .tmp suffix) without the lines of “known bad” data contained in the file “bad.txt”

 

 

 

Finally the old data files are deleted and the new temporary (.tmp) files are renamed (.dat)


Usage:
Copy the file prmclean.cmd into the folder containing the LR_TestData folder.  Create a text file in this folder called bad.txt containing the “known bad” data.  Run the prmclean.cmd command.

prmclean.cmd screenshot

Sample code:
A sample of this code which can be used to further develop this function is available here.

Performance problems ITV1 website and Tweetminster during leader’s debate

Dear ITV  & Tweetminster,

I’m a web application performance tester. I could have helped you avoid some of the load-related problems that caused problems for your customers during tonight’s debate.

stream_img

Sky and BBC, don’t forget to performance test your sites before the next debates !

Good Luck.