PathAppendA function

Appends one path to the end of another.

Note  Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchAppend or PathCchAppendEx function in its place.


BOOL PathAppendA(
  LPSTR  pszPath,
  LPCSTR pszMore




A pointer to a null-terminated string to which the path specified in pszMore is appended. You must set the size of this buffer to MAX_PATH to ensure that it is large enough to hold the returned string.



A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be appended.

Return Value

Type: BOOL

Returns TRUE if successful, or FALSE otherwise.


This function automatically inserts a backslash between the two strings, if one is not already present.

The path supplied in pszPath cannot begin with "..\" or ".\" to produce a relative path string. If present, those periods are stripped from the output string. For example, appending "path3" to "..\path1\path2" results in an output of "\path1\path2\path3" rather than "..\path1\path2\path3".


#include <windows.h>
#include <iostream>
#include "Shlwapi.h"

using namespace std;

int main( void )
	// String for path name.
	char buffer_1[MAX_PATH] = "name_1\\name_2";
	char *lpStr1;
	lpStr1 = buffer_1;

	// String of what is being added.
	char buffer_2[ ] = "name_3";
	char *lpStr2;
	lpStr2 = buffer_2;

	cout << "The original path string is    " << lpStr1 << endl;
	cout << "The part to append to end is   " << lpStr2 << endl;
	bool ret = PathAppend(lpStr1,lpStr2);
	cout << "The appended path string is    " << lpStr1 << endl;

The original path string is    name_1\name_2
The part to append to end is   name_3
The appended path string is    name_1\name_2\name_3


Minimum supported client Windows 2000 Professional, Windows XP [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header shlwapi.h
Library Shlwapi.lib
DLL Shlwapi.dll (version 4.71 or later)