Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check file exists in Groovy script

Workbook aWorkBook = Workbook.getWorkbook(new File("C:\\Users\\Response.xls"));     
WritableWorkbook workbook1 = Workbook.createWorkbook(new File("C:\\Users\\Responses.xls"), aWorkBook);

I am doing DATA DRIVEN TESTING using Groovy script in SOAP UI. Above is the part of the code where it is creating new file and then writing PASS or FAIL result to that excel. Suppose if have 5 testcases then I want to create new file only once in the first loop(1st testcase) then for next loop its should open the existing file.But currently it is creating new file in every loop and overriding the data and PASS result is displaying only for the last testcase. Can anyone help to resolve this?

like image 815
mona Avatar asked Dec 28 '25 18:12

mona


1 Answers

There is exists() method in File:

File file = new File("/path-to-file")
println file.exists()
like image 198
Evgeny Smirnov Avatar answered Jan 01 '26 11:01

Evgeny Smirnov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!