# Supplying filename arguments to launch files

I have a node that has a filename as a private parameter. The files can be located anywhere and have really long filenames. What I would like to do is

$roslaunch package_name launch_file.launch file:=reallylongfilename12345932.txt  where I running this command from the directory containing the file, so I can take advantage of tab-completing the filenames. I have an arg in my launch file called file that accepts this filename, but not the path. As a result, my node cannot open the file because it doesn't have the full path, just the name. Short of hardcoding in the path in the launch file, and being able to tab-complete the long file names, is there a way I can pass the full path of the file to my parameter? edit retag close merge delete ## 3 Answers Sort by » oldest newest most voted You can create a script that takes the name of the file as a parameter and forms the correct roslaunch call with the full path. So, if you have a package "mypackage", a launchfile "test.launch", than you could create a script mypackage/scripts/helper.bash : #!/bin/bash if [ "$1" != "" ]; then
echo "Full path to the file:"
echo "$PWD/$1"

roslaunch mypackage test.launch file:="$PWD/$1"
else
echo "$0: file not specified" fi  If you want to pass the filename "filename" from the local directory you could use the following command : rosrun mypackage helper.bash filename  more ## Comments Thanks, this is actually the approach I had taken but I was checking if there was some built-in functionality I didn't know about. Thanks again! ( 2015-06-29 11:32:45 -0500 )edit When using roslaunch it starts all nodes thinking they are in your ~/.ros/ directory. So you can create a symlink in your ~/.ros/ directory to the actual file you want to load. Then set your arg to look at the symlink by default. When creating the symlink you will be able to use tab completion. more I found this way to pass the current shell path to the xml launch file: <arg name="file_path" default="$(env PWD)"/>


and then the file name to read

<arg name="file_name"  default="file_name"/>


Finally, I pass the file name as a parameter to my C++ package:

<node pkg="pkg_name"  type="node_type"    name="node_name"  output="screen" >
<param name="file_name"  value="\$(arg file_name)"  type="string" />
</node>


Then, I use these arguments as entries for a C++ file in which I concatenate the two arguments.

Note : I get the value of these arguments in my C++ program through

std::string path, file;
ros::param::get("/node_name/file_path", path);
ros::param::get("/node_name/file_name", file);


I am using Ubuntu 18.04 with ROS Melodic. Hope it can help.

more