AAB
4 years agoRegular Contributor
ReadyAPI- append date in a filename
Hi all, I would like to fetch a file from my harddrive but each time I do so the DateTime should be appended after the filename and before the extension of the file. how could I do that please? ...
- 4 years agoPlease see if the below link is useful
https://stackoverflow.com/questions/1569547/does-groovy-have-an-easy-way-to-get-a-filename-without-the-extension - 4 years ago
Hi nmrao
Thanks for your response. I have given it a try and it worked! Thanks!
Solution:
// get document from path and append with DateTime //use the commons.io from apache //cfr https://community.smartbear.com/t5/API-Functional-Security-Testing/ReadyAPI-append-date-in-a-filename/m-p/221103#M49504 import org.apache.commons.io.FilenameUtils def path = testRunner.testCase.testSuite.project.getPropertyValue("pathDir") def getFile = new File(path + "\\CheatSheetGitBash.html") log.info getFile def date = new Date().format('yyMMddhhmm') log.info date //add a timestamp to the file def readName = getFile.getName() log.info readName //get the extension of the filename def getExtension = FilenameUtils.getExtension(readName) log.info getExtension //remove extension readName def filenameWithoutExtension = FilenameUtils.removeExtension(readName) log.info filenameWithoutExtension def addDate = filenameWithoutExtension + "${date}" as String log.info addDate def newFileName = addDate + "." + getExtension log.info newFileName