views:

289

answers:

1

I have a file that describes input data, which is split into several other files. In my descriptor file, I first give the path A that tells where all the other files are found.

The originator may set either a relative (to location of the descriptor file) or absolute path.

When my program is called, the user gives the name of the descriptor file. It may not be in the current working directory, so the filename B given may also contain directories.

For my program to always find the input files at the right places, I need to combine this information. If the path A given is absolute, I need to just that one. If it is relative, I need to concatenate it to the path B (i.e. directory portion of the filename).

I thought boost::filesystem::complete may do the job for me. Unfortunately, it seems it is not. I also did not understand how to test wether a path given is absolute or not.

Any ideas?

A: 

Actually I was quite misguided first but now found the solution myself. When "base" holds the path A, and filename holds B:

boost::filesystem::path basepath(base), filepath(filename);
if (!basepath.is_complete())
    basepath = filepath.remove_leaf() /= basepath;
base = basepath.string();

It works with Linux at least (where it would be very easy to do without boost, but oh well..), still have to test with Windows.

ypnos