PathRelativePathToPathRelativePathTo*
*



Contents  *



Index  *Topic Contents
*Previous Topic: PathQuoteSpaces
*Next Topic: PathRemoveArgs

PathRelativePathTo


BOOL PathRelativePathTo(
    LPTSTR  pszPath,
    LPCTSTR pszFrom,
    DWORD   dwAttrFrom,
    LPCTSTR pszTo,
    DWORD   dwAttrTo
    );

Creates a relative path from two paths.

pszPath
Address of a string that receives the relative path. This buffer is assumed to be at least MAX_PATH characters in size.
pszFrom
Address of a string that contains the path that pszPath will be relative from. This is the path in which the relative path can be used.
dwAttrFrom
File attributes of pszFrom. If this value contains FILE_ATTRIBUTE_DIRECTORY, pszFrom is assumed to be directory; otherwise, pszFrom is assumed to be a file.
pszTo
Address of a string that contains the path that pszPath will be relative to. The relative path will point to this path.
dwAttrTo
File attributes of pszTo. If this value contains FILE_ATTRIBUTE_DIRECTORY, pszTo is assumed to be directory; otherwise, pszTo is assumed to be a file.

Example:

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

void main( void )
{
    char szOut[MAX_PATH] = "";
    char szFrom[] = "c:\\a\\b\\path";
    char szTo[] = "c:\\a\\x\\y\\file";

    cout  <<  "The relative path is relative from: ";
    cout  <<  szFrom;
    cout  <<  "\n";

    cout  <<  "The relative path is relative to: ";
    cout  <<  szTo;
    cout  <<  "\n";

    PathRelativePathTo(  szOut,
                         szFrom,
                         FILE_ATTRIBUTE_DIRECTORY,
                         szTo,
                         FILE_ATTRIBUTE_NORMAL);

    cout  <<  "The relative path is: ";
    cout  <<  szOut;
    cout  <<  "\n";
}
OUTPUT:
==================
The relative path is relative from: c:\a\b\path
The relative path is relative to: c:\a\x\y\file
The relative path is: ..\x\y\file

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.