Overwrite of CSV file via jmeter

Advertisements

we are able to write dropdown of a needed variable of matchNr case to multiple CSV file’s in setup thread group with the below code

def cnt = Integer.parseInt(vars.get("value_matchNr"));
for(int i=1; i<=cnt; i++)
{
    def File f =new File('C:/INPUT/value.csv');
    f<<vars.get("value_"+i) << '\n';
}

i am not able to delete created files via batch file as it saying file got using in the backend, so i need to delete the contents of created files.

please help on this scenario, to overwrite

Batch file1: to delete csv files

echo
del "C:\Data*.csv" /s /f /q
echo Done!!

CMD used in jsr2253 sampler:
Runtime.getRuntime().exec("C:/Windows/System32/cmd.exe /c C:/DeleteInput.bat");

>Solution :

If the file is being used in CSV Data Set Config you won’t be able to delete it.

You can try removing the file somewhere in tearDown Thread Group using the following Groovy code invoking File.delete() function :

new File('input.csv').delete()

if it fails (although shouldn’t) you can consider using File.deleteOnExit() function instead

Quick test shows that the file created in setUp Thread Group and accessed in the "normal" Thread Group can be deleted without issues in the tearDown Thread Group:


If you want just to remove content you can call the following command:

new File('input.csv').text = ''

Leave a ReplyCancel reply