Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

PathStripPath (shlwapi)
 
.
Summary
Removes the path portion of a fully qualified path and file.

C# Signature:

[DllImport("shlwapi.dll", CharSet=CharSet.Auto)]
static extern void PathStripPath([In,Out] StringBuilder pszPath);

VB.NET Signature

''' <summary>
''' Removes the path portion of a fully qualified path and file.
''' </summary>
''' <param name="pszPath">A pointer to a null-terminated string of length MAX_PATH that contains the path and file name. When this function returns successfully, the string contains only the file name, with the path removed.</param>
<DllImport("shlwapi.dll", EntryPoint:="PathStripPathW",  SetLastError:=True, CharSet:=CharSet.Unicode)> _
Public Sub PathStripPath(<MarshalAs(UnmanagedType.LPTStr)>pszPath As System.Text.StringBuilder)
End Sub

VB Signature:

Public Declare Sub PathStripPath Lib "shlwapi" Alias "PathStripPathA" _
        (ByVal pszPath As String)
Declare Function PathStripPath Lib "shlwapi.dll" (TODO) As TODO

Notes:

This is similar, but not identical, to Path.GetFileName. If the input string ends with a directory, the directory is returned rather than nothing; for example, "C:\foo\" becomes "foo\", "C:" stays "C:".

Tips & Tricks:

Please add some!

Sample Code:

C# Example

StringBuilder str = new StringBuilder(@"c:\dir1\file.txt");
PathStripPath(str);
// Result: str.ToString() == "file.txt"

VB.NET Example

Dim strFile As New system.Text.StringBuilder(255)
strFile.Append("c:\abc\def\words.doc")
Win32.API.Shlwapi.PathStripPath(strFile)
System.Diagnostics.Debug.WriteLine(strFile.ToString())

Alternative Managed API:

Path.GetFileName

Path.GetFileName

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions