PathFindFileName function

Searches a path for a file name.

Syntax


PTSTR PathFindFileName(
  _In_  PTSTR pPath
);

Parameters

pPath [in]

Type: PTSTR

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

Return value

Type: PTSTR

Returns a pointer to the address of the string if successful, or a pointer to the beginning of the path otherwise.

Examples



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

void main( void )
{
    // Path that contains a file part.
    char buffer_1[ ] = "c:\\path\\file"; 
    char *lpStr1;
    lpStr1 = buffer_1;

    cout << "Search for the file in path        " << lpStr1
         << "\nReturns the file part of the path \""
         <<  PathFindFileName(lpStr1) << "\"" << endl;

    cout << "\nSearch for the file in path       \"c:\\path\"" << endl;
    cout << "Returns the file part of the path \""
         <<  PathFindFileName("c:\\path") << "\"" << endl;

    cout << "\nSearch for the file in path       \"c:\\path\\\"" << endl;
    cout << "Returns the file part of the path \""
         <<  PathFindFileName("c:\\path\\") << "\"" << endl;

    cout << "\nSearch for the file in path       \"c:\\\"" << endl;
    cout << "Returns the file part of the path \""
         <<  PathFindFileName("c:\\") << "\"" << endl;

    cout << "\nSearch for the file in path       \"c:\"" << endl;
    cout << "Returns the file part of the path \""
         <<  PathFindFileName("c:") << "\"" << endl;

    cout << "\nSearch for the file in path       \"path\"" << endl;
    cout << "Returns the file part of the path \""
         <<  PathFindFileName("path") << "\"" << endl;

OUTPUT:
==========
Search for the file in path        c:\path\file
Returns the file part of the path "file"

Search for the file in path       "c:\path"
Returns the file part of the path "path"

Search for the file in path       "c:\path\"
Returns the file part of the path "path\"

Search for the file in path       "c:\"
Returns the file part of the path "c:\"

Search for the file in path       "c:"
Returns the file part of the path "c:"

Search for the file in path       "path"
Returns the file part of the path "path"

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 4.71 or later)

Unicode and ANSI names

PathFindFileNameW (Unicode) and PathFindFileNameA (ANSI)

 

 

Community Additions

ADD
Show:
© 2014 Microsoft