Share via


_fullpath, _wfullpath

Create an absolute or full path name for the specified relative path name.

char*_fullpath(char*absPath,constchar*relPath,size_tmaxLength**);**

wchar_t*_wfullpath(wchar_t*absPath,constwchar_t*relPath,size_tmaxLength**);**

Function Required Header Compatibility
_fullpath <stdlib.h> Win 95, Win NT
_wfullpath <stdlib.h> or <wchar.h> Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns a pointer to a buffer containing the absolute path name (absPath). If there is an error (for example, if the value passed in relPath includes a drive letter that is not valid or cannot be found, or if the length of the created absolute path name (absPath) is greater than maxLength) the function returns NULL.

Parameters

absPath

Pointer to a buffer containing the absolute or full path name

relPath

Relative path name

maxLength

Maximum length of the absolute path name buffer (absPath). This length is in bytes for _fullpath but in wide characters (wchar_t) for _wfullpath.

Remarks

The _fullpath function expands the relative path name in relPath to its fully qualified or “absolute” path, and stores this name in absPath. A relative path name specifies a path to another location from the current location (such as the current working directory: “.”). An absolute path name is the expansion of a relative path name that states the entire path required to reach the desired location from the root of the filesystem. Unlike _makepath, _fullpath can be used to obtain the absolute path name for relative paths (relPath) that include “./” or “../” in their names.

For example, to use C run-time routines, the application must include the header files that contain the declarations for the routines. Each header file include statement references the location of the file in a relative manner (from the application’s working directory):

#include <stdlib.h>

when the absolute path (actual file system location) of the file may be:

\\machine\shareName\msvcSrc\crt\headerFiles\stdlib.h

_fullpath automatically handles multibyte-character string arguments as appropriate, recognizing multibyte-character sequences according to the multibyte code page currently in use. _wfullpath is a wide-character version of _fullpath; the string arguments to _wfullpath are wide-character strings. _wfullpath and _fullpath behave identically except that _wfullpath does not handle multibyte-character strings.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tfullpath _fullpath _fullpath _wfullpath

If the absPath buffer is NULL, _fullpath calls malloc to allocate a buffer of size _MAX_PATH and ignores the maxLength argument. It is the caller’s responsibility to deallocate this buffer (using free) as appropriate. If the relPath argument specifies a disk drive, the current directory of this drive is combined with the path.

Example

/* FULLPATH.C: This program demonstrates how _fullpath
 * creates a full path from a partial path.
 */

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <direct.h>

char full[_MAX_PATH], part[_MAX_PATH];

void main( void )
{
   while( 1 )
   {
      printf( "Enter partial path or ENTER to quit: " );
      gets( part );
      if( part[0] == 0 )
         break;

      if( _fullpath( full, part, _MAX_PATH ) != NULL )
         printf( "Full path is: %s\n", full );
      else
         printf( "Invalid path\n" );
   }
}

File Handling Routines

See Also   _getcwd, _getdcwd, _makepath, _splitpath