0
votes

Getting error message empty How to extract filename from path using beanshell Suppose filepath = /home/user/desktop/file.txt I want to get file.txt seperately using beanshell in jmeter

1

1 Answers

0
votes

You could use FilenameUtils.getPath() method like:

import org.apache.commons.io.FilenameUtils;

filepath = "/home/user/desktop/file.txt";
filename = FilenameUtils.getName(filepath);

log.info(filename);

Demo:

Beanshell get filename


Be aware that it is recommended to use JSR223 Elements and Groovy language instead of Beanshell, Groovy has better performance, it's more Java-compatible and it has some extra language features, see Apache Groovy - Why and How You Should Use It for more details.