3

Is there a function that returns the fully qualified path name for any inputted file?

I'm thinking of something like:

LPCSTR path = "foo.bar"
LPCSTR fullPath = FullyQualifiedPath(path);
//fullPath now equals C:\path\to\foo.bar

Thanks

EboMike
  • 76,846
  • 14
  • 164
  • 167
Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133

2 Answers2

4

In Win32, call the GetFullPathName function.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 2
    Note that on NTFS, with hard links especially, this returns one of the full path names of the file (if it only has one, then it doesn't matter). Just a head's up. – jrtipton Oct 27 '10 at 20:49
3

Use boost::filesystem http://www.boost.org/doc/libs/1_44_0/libs/filesystem/v2/doc/index.htm

#include <iostream>
#include <boost/filesystem.hpp>

int main()
{
    boost::filesystem::path p = boost::filesystem::complete("foo.bar");
    std::cout << p;
}
Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274