using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Vanara.PInvoke
{
public static partial class ShlwApi
{
/// Flags used by .
[PInvokeData("shlwapi.h", MSDNShortId = "bd9bf950-e349-4b67-8608-7acad84c0907")]
[Flags]
public enum PMSF
{
/// The pszSpec parameter points to a single file name pattern to be matched.
PMSF_NORMAL = 0x00000000,
/// The pszSpec parameter points to a semicolon-delimited list of file name patterns to be matched.
PMSF_MULTIPLE = 0x00000001,
///
/// If PMSF_NORMAL is used, ignore leading spaces in the string pointed to by pszSpec. If PMSF_MULTIPLE is used,
/// ignore leading spaces in each file type contained in the string pointed to by pszSpec. This flag can be combined with
/// PMSF_NORMAL and PMSF_MULTIPLE.
///
PMSF_DONT_STRIP_SPACES = 0x00010000,
}
///
///
/// Adds a backslash to the end of a string to create the correct syntax for a path. If the source path already has a trailing
/// backslash, no backslash will be added.
///
///
/// Note Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchAddBackslash or
/// PathCchAddBackslashEx function in its place.
///
///
///
/// TBD
///
///
/// Type: LPTSTR
///
/// A pointer that, when this function returns successfully, points to the new string's terminating null character. If the backslash
/// could not be appended due to inadequate buffer size, this value is NULL.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathaddbackslasha LPSTR PathAddBackslashA( LPSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "27d8aec7-8b00-412a-9a42-8ce27e262781")]
public static extern IntPtr PathAddBackslash(StringBuilder pszPath);
///
/// Adds a file name extension to a path string.
///
/// Note Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchAddExtension function
/// in its place.
///
///
///
/// Type: LPTSTR
///
/// A pointer to a buffer with the null-terminated string to which the file name extension will be appended. You must set the size of
/// this buffer to MAX_PATH to ensure that it is large enough to hold the returned string.
///
///
///
/// TBD
///
///
/// Type: BOOL
/// Returns TRUE if an extension was added, or FALSE otherwise.
///
///
///
/// If there is already a file name extension present, no extension will be added. If the pszPath points to a NULL string, the
/// result will be the file name extension only. If pszExtension points to a NULL string, an ".exe" extension will be added.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathaddextensiona BOOL PathAddExtensionA( LPSTR pszPath,
// LPCSTR pszExt );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "2c113d11-11d5-4362-bad5-c859d65aca2a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathAddExtension(StringBuilder pszPath, string pszExt);
///
/// 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.
///
///
///
/// Type: LPTSTR
///
/// 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.
///
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be appended.
///
///
/// 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".
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathappenda BOOL PathAppendA( LPSTR pszPath, LPCSTR
// pszMore );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "896737ef-a05c-4f0f-b8b0-56355ae9c2d9")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathAppend(StringBuilder pszPath, string pszMore);
///
/// Creates a root path from a given drive number.
///
///
/// TBD
///
///
/// Type: int
/// A variable of type int that indicates the desired drive number. It should be between 0 and 25.
///
///
/// Type: LPTSTR
///
/// Returns the address of the constructed root path. If the call fails for any reason (for example, an invalid drive number), szRoot
/// is returned unchanged.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathbuildroota LPSTR PathBuildRootA( LPSTR pszRoot, int
// iDrive );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "0a6895bd-54cf-499c-9057-f2d721bce5d9")]
public static extern IntPtr PathBuildRoot(StringBuilder pszRoot, int iDrive);
///
/// Simplifies a path by removing navigation elements such as "." and ".." to produce a direct, well-formed path.
///
/// Note Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchCanonicalize or
/// PathCchCanonicalizeEx function in its place.
///
///
///
/// TBD
///
///
/// TBD
///
///
/// Type: BOOL
///
/// Returns TRUE if a result has been computed and the content of the lpszDst output buffer is valid. Returns FALSE
/// otherwise, and the contents of the buffer pointed to by lpszDst are invalid. To get extended error information, call GetLastError.
///
///
///
///
/// This function allows the user to specify what to remove from a path by inserting special character sequences into the path. The
/// ".." sequence indicates to remove a path segment from the current position to the previous path segment. The "." sequence
/// indicates to skip over the next path segment to the following path segment. The root segment of the path cannot be removed.
///
///
/// If there are more ".." sequences than there are path segments, the function returns TRUE and contents of the buffer
/// pointed to by lpszDst contains just the root, "".
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathcanonicalizea BOOL PathCanonicalizeA( LPSTR pszBuf,
// LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "e9b1e877-2cd6-4dd9-a15b-676cb940daed")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathCanonicalize(StringBuilder pszBuf, string pszPath);
///
/// Concatenates two strings that represent properly formed paths into one path; also concatenates any relative path elements.
///
/// Note Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchCombine or
/// PathCchCombineEx function in its place.
///
///
///
/// TBD
///
///
/// TBD
///
///
/// TBD
///
///
/// Type: LPTSTR
///
/// A pointer to a buffer that, when this function returns successfully, receives the concatenated path string. This is the same
/// string pointed to by pszPathOut. If this function does not return successfully, this value is NULL.
///
///
///
///
/// The directory path should be in the form of A:,B:, ..., Z:. The file path should be in a correct form that represents the file
/// name part of the path. If the directory path ends with a backslash, the backslash will be maintained. Note that while lpszDir and
/// lpszFile are both optional parameters, they cannot both be NULL.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathcombinea LPSTR PathCombineA( LPSTR pszDest, LPCSTR
// pszDir, LPCSTR pszFile );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "ed03334b-f688-4993-9685-092135ca29c9")]
public static extern IntPtr PathCombine(StringBuilder pszDest, string pszDir, string pszFile);
///
/// Compares two paths to determine if they share a common prefix. A prefix is one of these types: "C:\", ".", "..", "..\".
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of length MAX_PATH that contains the first path name.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of length MAX_PATH that contains the second path name.
///
///
/// TBD
///
///
/// Type: int
///
/// Returns the count of common prefix characters in the path. If the output buffer pointer is not NULL, then these characters
/// are copied to the output buffer.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathcommonprefixa int PathCommonPrefixA( LPCSTR pszFile1,
// LPCSTR pszFile2, LPSTR achPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "13c32b32-8541-41c4-82d8-48d3b2439f0c")]
public static extern int PathCommonPrefix(string pszFile1, string pszFile2, StringBuilder achPath);
///
/// Truncates a file path to fit within a given pixel width by replacing path components with ellipses.
///
///
/// Type: HDC
/// A handle to the device context used for font metrics. This value can be NULL.
///
///
/// TBD
///
///
/// Type: UINT
/// The width, in pixels, in which the string must fit.
///
///
/// Type: BOOL
///
/// Returns TRUE if the path was successfully compacted to the specified width. Returns FALSE on failure, or if the
/// base portion of the path would not fit the specified width.
///
///
///
///
/// This function uses the font currently selected in hDC to calculate the width of the text. This function will not compact the path
/// beyond the base file name preceded by ellipses.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathcompactpatha BOOL PathCompactPathA( HDC hDC, LPSTR
// pszPath, UINT dx );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "b8184c98-1f86-4714-baf8-af4ef3e71cf2")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathCompactPath(HDC hDC, StringBuilder pszPath, uint dx);
///
/// Truncates a path to fit within a certain number of characters by replacing path components with ellipses.
///
///
/// Type: LPTSTR
/// The address of the string that has been altered.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of length MAX_PATH that contains the path to be altered.
///
///
/// Type: UINT
///
/// The maximum number of characters to be contained in the new string, including the terminating null character. For example, if
/// cchMax = 8, the resulting string can contain a maximum of 7 characters plus the terminating null character.
///
///
///
/// Type: DWORD
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// The '/' separator will be used instead of '' if the original string used it. If pszSrc points to a file name that is too long,
/// instead of a path, the file name will be truncated to cchMax characters, including the ellipsis and the terminating NULL
/// character. For example, if the input file name is "My Filename" and cchMax is 10, PathCompactPathEx will return "My Fil...".
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathcompactpathexa BOOL PathCompactPathExA( LPSTR pszOut,
// LPCSTR pszSrc, UINT cchMax, DWORD dwFlags );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "ff108ee6-3d71-4ab2-a04a-d4bcce408f88")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathCompactPathEx(StringBuilder pszOut, string pszSrc, uint cchMax, uint dwFlags = 0);
///
/// Converts a file URL to a Microsoft MS-DOS path.
///
///
/// Type: PCTSTR
/// A null-terminated string of maximum length INTERNET_MAX_URL_LENGTH that contains the URL.
///
///
/// Type: PTSTR
///
/// A pointer to a buffer that, when this function returns successfully, receives the MS-DOS path. You must set the size of this
/// buffer to MAX_PATH to ensure that it is large enough to hold the returned string.
///
///
///
/// Type: DWORD*
/// The number of characters in the pszPath buffer.
///
///
/// Type: DWORD
/// Reserved. Set this parameter to NULL.
///
///
/// Type: HRESULT
/// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathcreatefromurla LWSTDAPI PathCreateFromUrlA( PCSTR
// pszUrl, PSTR pszPath, DWORD *pcchPath, DWORD dwFlags );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "f4136c80-a309-4551-be73-f2f24ecd4675")]
public static extern HRESULT PathCreateFromUrl(string pszUrl, StringBuilder pszPath, ref uint pcchPath, uint dwFlags = 0);
///
/// Creates a path from a file URL.
///
///
/// Type: PCWSTR
/// A pointer to the URL of a file, represented as a null-terminated, Unicode string.
///
///
/// Type: PWSTR*
///
/// The address of a pointer to a buffer of length MAX_PATH that, when this function returns successfully, receives the file path.
///
///
///
/// Type: DWORD
/// Reserved, must be 0.
///
///
/// Type: HRESULT
/// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathcreatefromurlalloc LWSTDAPI PathCreateFromUrlAlloc(
// PCWSTR pszIn, PWSTR *ppszOut, DWORD dwFlags );
[DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("shlwapi.h", MSDNShortId = "274411cd-5922-4db8-8775-feb93cae32dd")]
public static extern HRESULT PathCreateFromUrlAlloc(string pszIn, ref StringBuilder ppszOut, uint dwFlags = 0);
///
/// Determines whether a path to a file system object such as a file or folder is valid.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the full path of the object to verify.
///
///
/// Type: BOOL
/// TRUE if the file exists; otherwise, FALSE. Call GetLastError for extended error information.
///
///
/// This function tests the validity of the path.
///
/// A path specified by Universal Naming Convention (UNC) is limited to a file only; that is, \server\share\file is permitted. A UNC
/// path to a server or server share is not permitted; that is, \server or \server\share. This function returns FALSE if a
/// mounted remote drive is out of service.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfileexistsa BOOL PathFileExistsA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "26d01e9f-cbf2-4e40-9970-a594879b424d")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathFileExists(string pszPath);
///
/// Searches a path for an extension.
///
///
/// Type: PTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to search, including the extension being
/// searched for.
///
///
///
/// Type: PTSTR
///
/// Returns the address of the "." that precedes the extension within pszPath if an extension is found, or the address of the
/// terminating null character otherwise.
///
///
///
///
/// Note that a valid file name extension cannot contain a space. For more information on valid file name extensions, see File Type Handlers.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindextensiona LPCSTR PathFindExtensionA( LPCSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "afebd4b7-2685-4b6e-8f8a-d43944dacef5")]
public static extern IntPtr PathFindExtension(string pszPath);
///
/// Searches a path for a file name.
///
///
/// TBD
///
///
/// Type: PTSTR
/// Returns a pointer to the address of the string if successful, or a pointer to the beginning of the path otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindfilenamea LPCSTR PathFindFileNameA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "f3824dee-1169-4f89-9844-35aa8a1830c4")]
public static extern IntPtr PathFindFileName(string pszPath);
///
/// Parses a path and returns the portion of that path that follows the first backslash.
///
///
/// Type: PTSTR
///
/// A pointer to a null-terminated string that contains the path to parse. This string must not be longer than MAX_PATH characters,
/// plus the terminating null character. Path components are delimited by backslashes. For instance, the path
/// "c:\path1\path2\file.txt" has four components: c:, path1, path2, and file.txt.
///
///
///
/// Type: PTSTR
/// Returns a pointer to a null-terminated string that contains the truncated path.
/// If pszPath points to the last component in the path, this function returns a pointer to the terminating null character.
/// If pszPath points to the terminating null character or if the call fails, this function returns NULL.
///
///
///
/// PathFindNextComponent walks a path string until it encounters a backslash ("\"), ignores everything up to that point
/// including the backslash, and returns the rest of the path. Therefore, if a path begins with a backslash (such as \path1\path2),
/// the function simply removes the initial backslash and returns the rest (path1\path2).
///
/// Examples
///
/// The following simple console application passes various strings to PathFindNextComponent to demonstrate what the function
/// recognizes as a path component and to show what is returned. To run this code in Visual Studio, you must link to Shlwapi.lib and
/// define UNICODE in the preprocessor commands in the project settings.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindnextcomponenta LPCSTR PathFindNextComponentA(
// LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "2c76b901-dc0e-4f26-93c8-3c59b8f7147d")]
public static extern IntPtr PathFindNextComponent(string pszPath);
///
/// Searches for a file.
///
///
/// TBD
///
///
/// Type: LPCTSTR*
/// An optional, null-terminated array of directories to be searched first. This value can be NULL.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// PathFindOnPath searches for the file specified by pszFile. If no directories are specified in ppszOtherDirs, it attempts
/// to find the file by searching standard directories such as System32 and the directories specified in the PATH environment
/// variable. To expedite the process or enable PathFindOnPath to search a wider range of directories, use the ppszOtherDirs
/// parameter to specify one or more directories to be searched first. If more than one file has the name specified by pszFile,
/// PathFindOnPath returns the first instance it finds.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpatha BOOL PathFindOnPathA( LPSTR pszPath,
// PZPCSTR ppszOtherDirs );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "d9281eb2-39b7-444f-85b7-1e1e76c38ae2")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathFindOnPath(StringBuilder pszPath, [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPTStr)] string[] ppszOtherDirs);
///
/// Determines whether a given file name has one of a list of suffixes.
///
///
/// Type: LPCTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the file name to be tested. A full path can be used.
///
///
///
/// Type: const LPCTSTR*
///
/// An array of iArraySize string pointers. Each string pointed to is null-terminated and contains one suffix. The strings can be of
/// variable lengths.
///
///
///
/// Type: int
/// The number of elements in the array pointed to by apszSuffix.
///
///
/// Type: LPCTSTR
///
/// Returns a pointer to a string with the matching suffix if successful, or NULL if pszPath does not end with one of the
/// specified suffixes.
///
///
///
/// This function uses a case-sensitive comparison. The suffix must match exactly.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindsuffixarraya LPCSTR PathFindSuffixArrayA( LPCSTR
// pszPath, const LPCSTR *apszSuffix, int iArraySize );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "e2285f7d-bb5d-48c5-bdf1-10ca410389f0")]
public static extern IntPtr PathFindSuffixArray(string pszPath, string[] apszSuffix, int iArraySize);
///
/// Finds the command line arguments within a given path.
///
///
/// Type: PTSTR
/// Pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be searched.
///
///
/// Type: PTSTR
/// Returns a pointer to a null-terminated string that contains the arguments portion of the path if successful.
/// If there are no arguments in the path, the function returns a pointer to the end of the input string.
/// If the function is given a NULL argument it returns NULL.
///
///
///
/// This function should not be used on generic command path templates (from users or the registry), but rather should be used only
/// on templates that the application knows to be well formed.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathgetargsa LPCSTR PathGetArgsA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "17dfb601-1306-41b6-a504-8bf69ff204c9")]
public static extern IntPtr PathGetArgs(string pszPath);
///
/// Determines the type of character in relation to a path.
///
///
/// Type: TUCHAR
/// The character for which to determine the type.
///
///
/// Type: UINT
/// Returns one or more of the following values that define the type of character.
///
///
/// Return code
/// Description
///
/// -
/// GCT_INVALID
/// The character is not valid in a path.
///
/// -
/// GCT_LFNCHAR
/// The character is valid in a long file name.
///
/// -
/// GCT_SEPARATOR
/// The character is a path separator.
///
/// -
/// GCT_SHORTCHAR
/// The character is valid in a short (8.3) file name.
///
/// -
/// GCT_WILD
/// The character is a wildcard character.
///
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathgetchartypea UINT PathGetCharTypeA( UCHAR ch );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "838a255f-413e-424c-819e-47265224208d")]
public static extern GCT PathGetCharType(char ch);
///
/// Searches a path for a drive letter within the range of 'A' to 'Z' and returns the corresponding drive number.
///
///
/// TBD
///
///
/// Type: int
/// Returns 0 through 25 (corresponding to 'A' through 'Z') if the path has a drive letter, or -1 otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathgetdrivenumbera int PathGetDriveNumberA( LPCSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "38914866-fdd4-47f2-b0e7-d09d1cfb0eee")]
public static extern int PathGetDriveNumber(string pszPath);
///
///
/// Determines if a file's registered content type matches the specified content type. This function obtains the content type for the
/// specified file type and compares that string with the pszContentType. The comparison is not case-sensitive.
///
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the file whose content type will be compared.
///
///
/// Type: LPCTSTR
///
/// The address of a character buffer that contains the null-terminated content type string to which the file's registered content
/// type will be compared.
///
///
///
/// Type: BOOL
/// Returns nonzero if the file's registered content type matches pszContentType, or zero otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathiscontenttypea BOOL PathIsContentTypeA( LPCSTR
// pszPath, LPCSTR pszContentType );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "53eac496-9666-41fc-8682-f7b6583a62fe")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsContentType(string pszPath, string pszContentType);
///
/// Verifies that a path is a valid directory.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to verify.
///
///
/// Type: BOOL
/// Returns (BOOL)FILE_ATTRIBUTE_DIRECTORY if the path is a valid directory; otherwise, FALSE.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisdirectorya BOOL PathIsDirectoryA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "9af3e3da-6b3a-4e81-ba50-ff7aeeb73c44")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsDirectory(string pszPath);
///
/// Determines whether a specified path is an empty directory.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be tested.
///
///
/// Type: BOOL
///
/// Returns TRUE if pszPath is an empty directory. Returns FALSE if pszPath is not a directory, or if it contains at
/// least one file other than "." or "..".
///
///
///
/// "C:" is considered a directory.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisdirectoryemptya BOOL PathIsDirectoryEmptyA( LPCSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "833fe68e-8b21-4819-8370-d1b5391a3080")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsDirectoryEmpty(string pszPath);
///
///
/// Searches a path for any path-delimiting characters (for example, ':' or '' ). If there are no path-delimiting characters present,
/// the path is considered to be a File Spec path.
///
///
///
/// TBD
///
///
/// Type: BOOL
///
/// Returns TRUE if there are no path-delimiting characters within the path, or FALSE if there are path-delimiting characters.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisfilespeca BOOL PathIsFileSpecA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "c69d6cca-44e7-4792-8fb2-3c4ecd2e57f2")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsFileSpec(string pszPath);
///
/// Determines whether a file name is in long format.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the file name to be tested.
///
///
/// Type: BOOL
/// Returns TRUE if pszName exceeds the number of characters allowed by the 8.3 format, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathislfnfilespeca BOOL PathIsLFNFileSpecA( LPCSTR pszName );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "599cb457-da72-4416-bfb7-5bc55a0eeb2d")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsLFNFileSpec(string pszName);
///
/// Determines whether a path string represents a network resource.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path.
///
///
/// Type: BOOL
/// Returns TRUE if the string represents a network resource, or FALSE otherwise.
///
///
/// PathIsNetworkPath interprets the following two types of paths as network paths.
///
/// -
/// Paths that begin with two backslash characters (\\) are interpreted as Universal Naming Convention (UNC) paths.
///
/// -
///
/// Paths that begin with a letter followed by a colon (:) are interpreted as a mounted network drive. However,
/// PathIsNetworkPath cannot recognize a network drive mapped to a drive letter through the Microsoft MS-DOS SUBST command or
/// the DefineDosDevice function.
///
///
///
///
/// Note The function does not verify that the specified network resource exists, is currently accessible, or that the user
/// has sufficient permissions to access it.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisnetworkpatha BOOL PathIsNetworkPathA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "3a9c33bc-2325-4285-b6c3-4c3e1d323c1e")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsNetworkPath(string pszPath);
///
///
/// Searches a path to determine if it contains a valid prefix of the type passed by pszPrefix. A prefix is one of these types:
/// "C:\", ".", "..", "..\".
///
///
///
/// Type: IN LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the prefix for which to search.
///
///
/// Type: IN LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be searched.
///
///
/// Type: BOOL
/// Returns TRUE if the compared path is the full prefix for the path, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisprefixa BOOL PathIsPrefixA( LPCSTR pszPrefix, LPCSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "b24f761e-6492-4a6d-9c7e-d5a5f2cbdaf3")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsPrefix(string pszPrefix, string pszPath);
///
/// Searches a path and determines if it is relative.
///
///
/// TBD
///
///
/// Type: BOOL
/// Returns TRUE if the path is relative, or FALSE if it is absolute.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisrelativea BOOL PathIsRelativeA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "ad36c277-645f-4c62-af7d-b75e29de573f")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsRelative(string pszPath);
///
/// Determines whether a path string refers to the root of a volume.
///
///
/// TBD
///
///
/// Type: BOOL
/// Returns TRUE if the specified path is a root, or FALSE otherwise.
///
///
///
/// Returns TRUE for paths such as "", "X:" or "\server<i>share". Paths such as "..\path2" or "\server" return FALSE.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisroota BOOL PathIsRootA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "8586df98-91c4-49a6-9b07-7dceb8a63431")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsRoot(string pszPath);
///
/// Compares two paths to determine if they have a common root component.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the first path to be compared.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the second path to be compared.
///
///
/// Type: BOOL
///
/// Returns TRUE if both strings have the same root component, or FALSE otherwise. If pszPath1 contains only the server
/// and share, this function also returns FALSE.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathissameroota BOOL PathIsSameRootA( LPCSTR pszPath1,
// LPCSTR pszPath2 );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "3409a8f1-e22c-4c13-961e-211a2d10fe10")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsSameRoot(string pszPath1, string pszPath2);
///
///
/// Determines if an existing folder contains the attributes that make it a system folder. Alternately, this function indicates if
/// certain attributes qualify a folder to be a system folder.
///
///
///
/// Type: LPCTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the name of an existing folder. The attributes for
/// this folder will be retrieved and compared with those that define a system folder. If this folder contains the attributes to make
/// it a system folder, the function returns nonzero. If this value is NULL, this function determines if the attributes passed
/// in dwAttrb qualify it to be a system folder.
///
///
///
/// Type: DWORD
///
/// The file attributes to be compared. Used only if pszPath is NULL. In that case, the attributes passed in this value are
/// compared with those that qualify a folder as a system folder. If the attributes are sufficient to make this a system folder, this
/// function returns nonzero. These attributes are the attributes that are returned from GetFileAttributes.
///
///
///
/// Type: BOOL
/// Returns nonzero if the pszPath or dwAttrb represent a system folder, or zero otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathissystemfoldera BOOL PathIsSystemFolderA( LPCSTR
// pszPath, DWORD dwAttrb );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "796901a8-1bc1-4fd1-b5b8-acd8f930ff14")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsSystemFolder(string pszPath, FileFlagsAndAttributes dwAttrb);
///
/// Determines if a path string is a valid Universal Naming Convention (UNC) path, as opposed to a path based on a drive letter.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to validate.
///
///
/// Type: BOOL
/// Returns TRUE if the string is a valid UNC path; otherwise, FALSE.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisunca BOOL PathIsUNCA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "53da5ba7-a2a4-45b2-90e0-ae006415933e")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsUNC(string pszPath);
///
/// Determines if a string is a valid Universal Naming Convention (UNC) for a server path only.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to validate.
///
///
/// Type: BOOL
/// Returns TRUE if the string is a valid UNC path for a server only (no share name), or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisuncservera BOOL PathIsUNCServerA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "9158ceb6-dd20-4b1a-93d3-cf7a5a5c6c75")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsUNCServer(string pszPath);
///
/// Determines if a string is a valid Universal Naming Convention (UNC) share path, \server<i>share.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be validated.
///
///
/// Type: BOOL
/// Returns TRUE if the string is in the form \server<i>share, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisuncserversharea BOOL PathIsUNCServerShareA( LPCSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "306cfc34-7cb2-4f60-af5c-8b567149c2fc")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsUNCServerShare(string pszPath);
///
/// Tests a given string to determine if it conforms to a valid URL format.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the URL path to validate.
///
///
/// Type: BOOL
/// Returns TRUE if pszPath has a valid URL format, or FALSE otherwise.
///
///
/// This function does not verify that the path points to an existing site—only that it has a valid URL format.
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisurla BOOL PathIsURLA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "8791bcd8-0d8f-4f7b-9c8e-59bcb95b5d19")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathIsURL(string pszPath);
///
/// Converts an all-uppercase path to all lowercase characters to give the path a consistent appearance.
///
///
/// TBD
///
///
/// Type: BOOL
/// Returns TRUE if the path has been converted, or FALSE otherwise.
///
///
///
/// This function only operates on paths that are entirely uppercase. For example: C:\WINDOWS will be converted to c:\windows, but
/// c:\Windows will not be changed.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathmakeprettya BOOL PathMakePrettyA( LPSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "fb871054-4c63-42de-b85b-edefa4b09ea0")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathMakePretty(StringBuilder pszPath);
///
/// Gives an existing folder the proper attributes to become a system folder.
///
///
/// Type: LPTSTR
///
/// A pointer to a null-terminated string of length MAX_PATH that contains the name of an existing folder that will be made into a
/// system folder.
///
///
///
/// Type: BOOL
/// Returns nonzero if successful, or zero otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathmakesystemfoldera BOOL PathMakeSystemFolderA( LPCSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "5b0faeb8-f8ae-481b-b5b2-cae9efe638e5")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathMakeSystemFolder(string pszPath);
///
/// Searches a string using a Microsoft MS-DOS wildcard match type.
///
///
/// Type: LPCSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be searched.
///
///
/// Type: LPCSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the file type for which to search. For example, to
/// test whether pszFile is a .doc file, pszSpec should be set to "*.doc".
///
///
///
/// Type: BOOL
/// Returns TRUE if the string matches, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathmatchspeca BOOL PathMatchSpecA( LPCSTR pszFile, LPCSTR
// pszSpec );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "908e7204-d168-4179-9c7b-ad46ba68bebc")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathMatchSpec(string pszFile, string pszSpec);
///
/// Matches a file name from a path against one or more file name patterns.
///
///
/// Type: LPCTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path from which the file name to be matched is taken.
///
///
///
/// Type: LPCTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the file name pattern for which to search. This
/// can be the exact name, or it can contain wildcard characters. If exactly one pattern is specified, set the PMSF_NORMAL
/// flag in dwFlags. If more than one pattern is specified, separate them with semicolons and set the PMSF_MULTIPLE flag.
///
///
///
/// Type: DWORD
/// Modifies the search condition. The following are valid flags.
/// PMSF_NORMAL (0x00000000)
/// The pszSpec parameter points to a single file name pattern to be matched.
/// PMSF_MULTIPLE (0x00000001)
/// The pszSpec parameter points to a semicolon-delimited list of file name patterns to be matched.
/// PMSF_DONT_STRIP_SPACES (0x00010000)
///
/// If PMSF_NORMAL is used, ignore leading spaces in the string pointed to by pszSpec. If PMSF_MULTIPLE is used, ignore
/// leading spaces in each file type contained in the string pointed to by pszSpec. This flag can be combined with PMSF_NORMAL
/// and PMSF_MULTIPLE.
///
///
///
/// Type: HRESULT
/// Returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// A file name pattern specified in pszSpec matched the file name found in the string pointed to by pszFile.
///
/// -
/// S_FALSE
/// No file name pattern specified in pszSpec matched the file name found in the string pointed to by pszFile.
///
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathmatchspecexa LWSTDAPI PathMatchSpecExA( LPCSTR
// pszFile, LPCSTR pszSpec, DWORD dwFlags );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "bd9bf950-e349-4b67-8608-7acad84c0907")]
public static extern HRESULT PathMatchSpecEx(string pszFile, string pszSpec, PMSF dwFlags);
///
/// Parses a file location string that contains a file location and icon index, and returns separate values.
///
///
/// Type: LPTSTR
///
/// A pointer to a null-terminated string of length MAX_PATH that contains a file location string. It should be in the form
/// "path,iconindex". When the function returns, pszIconFile will point to the file's path.
///
///
///
/// Type: int
/// Returns the valid icon index value.
///
///
///
/// This function is useful for taking a DefaultIcon value retrieved from the registry by SHGetValue and separating the icon index
/// from the path.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathparseiconlocationa int PathParseIconLocationA( LPSTR
// pszIconFile );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "1ded2f0f-0e11-4730-ab7b-16536e7f4435")]
public static extern int PathParseIconLocation(StringBuilder pszIconFile);
///
/// Searches a path for spaces. If spaces are found, the entire path is enclosed in quotation marks.
///
///
/// Type: LPTSTR
///
/// A pointer to a null-terminated string that contains the path to search. The size of this buffer must be set to MAX_PATH to ensure
/// that it is large enough to hold the returned string.
///
///
///
/// Type: BOOL
/// TRUE if spaces were found; otherwise, FALSE.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathquotespacesa BOOL PathQuoteSpacesA( LPSTR lpsz );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "76a51c21-b924-4919-a6bb-8c6bdec5b3f0")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathQuoteSpaces(StringBuilder lpsz);
///
/// Creates a relative path from one file or folder to another.
///
///
/// Type: LPTSTR
/// A pointer to a string that receives the relative path. This buffer must be at least MAX_PATH characters in size.
///
///
/// Type: LPCTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path that defines the start of the relative path.
///
///
///
/// Type: DWORD
///
/// The file attributes of pszFrom. If this value contains FILE_ATTRIBUTE_DIRECTORY, pszFrom is assumed to be a directory; otherwise,
/// pszFrom is assumed to be a file.
///
///
///
/// Type: LPCTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path that defines the endpoint of the relative path.
///
///
///
/// Type: DWORD
///
/// The 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.
///
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// This function takes a pair of paths and generates a relative path from one to the other. The paths do not have to be fully
/// qualified, but they must have a common prefix, or the function will fail and return FALSE.
///
///
/// For example, let the starting point, pszFrom, be "c:\FolderA\FolderB\FolderC", and the ending point, pszTo, be
/// "c:\FolderA\FolderD\FolderE". PathRelativePathTo will return the relative path from pszFrom to pszTo as:
/// "....\FolderD\FolderE". You will get the same result if you set pszFrom to "\FolderA\FolderB\FolderC" and pszTo to
/// "\FolderA\FolderD\FolderE". On the other hand, "c:\FolderA\FolderB" and "a:\FolderA\FolderD do not share a common prefix, and the
/// function will fail. Note that "\" is not considered a prefix and is ignored. If you set pszFrom to "\FolderA\FolderB", and pszTo
/// to "\FolderC\FolderD", the function will fail.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathrelativepathtoa BOOL PathRelativePathToA( LPSTR
// pszPath, LPCSTR pszFrom, DWORD dwAttrFrom, LPCSTR pszTo, DWORD dwAttrTo );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "7ed8d50a-2ad4-4ddf-941d-aea593341592")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathRelativePathTo(StringBuilder pszPath, string pszFrom, FileFlagsAndAttributes dwAttrFrom, string pszTo, FileFlagsAndAttributes dwAttrTo);
///
/// Removes any arguments from a given path.
///
///
/// Type: LPTSTR
/// Pointer to a null-terminated string of length MAX_PATH that contains the path from which to remove arguments.
///
///
/// This function does not return a value.
///
///
///
/// This function should not be used on generic command path templates (from users or the registry), but rather it should be used
/// only on templates that the application knows to be well formed.
///
/// Examples
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathremoveargsa void PathRemoveArgsA( LPSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "430072bc-4ddc-4b3d-bf32-fb60d7b56faf")]
public static extern void PathRemoveArgs(StringBuilder pszPath);
///
/// Removes the trailing backslash from a given path.
///
/// Note This function is deprecated. We recommend the use of the PathCchRemoveBackslash or PathCchRemoveBackslashEx function
/// in its place.
///
///
///
/// TBD
///
///
/// Type: LPTSTR
///
/// A pointer that, when this function returns successfully and if a backslash has been removed, points to the terminating null
/// character that has replaced the backslash at the end of the string. If the path did not include a trailing backslash, this value
/// will point to the final character in the string.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathremovebackslasha LPSTR PathRemoveBackslashA( LPSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "58d13c38-40aa-4aaa-81dc-2b68425f1fe0")]
public static extern IntPtr PathRemoveBackslash(StringBuilder pszPath);
///
/// Removes all leading and trailing spaces from a string.
///
///
/// TBD
///
///
/// This function does not return a value.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathremoveblanksa void PathRemoveBlanksA( LPSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "0f496855-3ea7-4193-b895-fd4ea26ef6c5")]
public static extern void PathRemoveBlanks(StringBuilder pszPath);
///
/// Removes the file name extension from a path, if one is present.
/// Note This function is deprecated. We recommend the use of the PathCchRemoveExtension in its place.
///
///
/// Type: LPTSTR
/// A pointer to a null-terminated string of length MAX_PATH from which to remove the extension.
///
///
/// This function does not return a value.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathremoveextensiona void PathRemoveExtensionA( LPSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "6e26d005-50af-4376-b734-19ba3d9c470f")]
public static extern void PathRemoveExtension(StringBuilder pszPath);
///
/// Removes the trailing file name and backslash from a path, if they are present.
/// Note This function is deprecated. We recommend the use of the PathCchRemoveFileSpec function in its place.
///
///
/// Type: LPTSTR
/// A pointer to a null-terminated string of length MAX_PATH that contains the path from which to remove the file name.
///
///
/// Type: BOOL
/// Returns nonzero if something was removed, or zero otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathremovefilespeca BOOL PathRemoveFileSpecA( LPSTR
// pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "c47bcf8a-c59d-4d6a-81a9-a3960ae39867")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathRemoveFileSpec(StringBuilder pszPath);
///
///
/// Replaces the extension of a file name with a new extension. If the file name does not contain an extension, the extension will be
/// attached to the end of the string.
///
///
/// Note Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchRenameExtension
/// function in its place.
///
///
///
/// Type: LPTSTR
/// Pointer to a null-terminated string of length MAX_PATH in which to replace the extension.
///
///
/// Type: LPCTSTR
/// Pointer to a character buffer that contains a '.' character followed by the new extension.
///
///
/// Type: BOOL
/// Returns nonzero if successful, or zero if the new path and extension would exceed MAX_PATH characters.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathrenameextensiona BOOL PathRenameExtensionA( LPSTR
// pszPath, LPCSTR pszExt );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "3d94f67c-e3ee-4b64-b0b9-8f771423bdc5")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathRenameExtension(StringBuilder pszPath, string pszExt);
///
/// Determines if a given path is correctly formatted and fully qualified.
///
///
/// TBD
///
///
/// TBD
///
///
/// TBD
///
///
/// Type: BOOL
/// Returns TRUE if the path is qualified, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathsearchandqualifya BOOL PathSearchAndQualifyA( LPCSTR
// pszPath, LPSTR pszBuf, UINT cchBuf );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "90da281d-349a-460a-aa5a-14e3b4ced727")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathSearchAndQualify(string pszPath, StringBuilder pszBuf, uint cchBuf);
///
/// Sets the text of a child control in a window or dialog box, using PathCompactPath to ensure the path fits in the control.
///
///
/// Type: HWND
/// A handle to the dialog box or window.
///
///
/// Type: int
/// The identifier of the control.
///
///
/// Type: LPCSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to set in the control.
///
///
/// This function does not return a value.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathsetdlgitempatha void PathSetDlgItemPathA( HWND hDlg,
// int id, LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "05737525-d906-482c-847f-bdbf0ba0ce3d")]
public static extern void PathSetDlgItemPath(HWND hDlg, int id, string pszPath);
///
///
/// Retrieves a pointer to the first character in a path following the drive letter or Universal Naming Convention (UNC) server/share
/// path elements.
///
///
///
/// Type: PTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to parse.
///
///
/// Type: PTSTR
///
/// A pointer that, when this function returns successfully, points to the beginning of the subpath that follows the root (drive
/// letter or UNC server/share). If the function encounters an error, this value will be NULL.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathskiproota LPCSTR PathSkipRootA( LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "528a3953-26d7-4fff-be31-9c9788d429ab")]
public static extern IntPtr PathSkipRoot(string pszPath);
///
/// Removes the path portion of a fully qualified path and file.
///
///
/// Type: LPTSTR
///
/// 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.
///
///
///
/// This function does not return a value.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathstrippatha void PathStripPathA( LPSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "84b439f2-f570-4e7f-bc3f-e0fdd185ea15")]
public static extern void PathStripPath(StringBuilder pszPath);
///
/// Removes all file and directory elements in a path except for the root information.
///
/// Note Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchStripToRoot function
/// in its place.
///
///
///
/// TBD
///
///
/// Type: BOOL
/// Returns TRUE if a valid drive letter was found in the path, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathstriptoroota BOOL PathStripToRootA( LPSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "ce9a1a40-2a03-44d2-80bc-0dc10654550b")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathStripToRoot(StringBuilder pszPath);
///
/// Removes the decoration from a path string.
///
///
/// Type: LPTSTR
///
/// A null-terminated string of length MAX_PATH that contains the path. When the function returns, pszPath points to the undecorated string.
///
///
///
/// This function does not return a value.
///
///
///
/// A decoration consists of a pair of square brackets with one or more digits in between, inserted immediately after the base name
/// and before the file name extension.
///
/// Examples
/// The following table illustrates how strings are modified by PathUndecorate.
///
///
/// Initial String
/// Undecorated String
///
/// -
/// C:\Path\File[5].txt
/// C:\Path\File.txt
///
/// -
/// C:\Path\File[12]
/// C:\Path\File
///
/// -
/// C:\Path\File.txt
/// C:\Path\File.txt
///
/// -
/// C:\Path\[3].txt
/// C:\Path\[3].txt
///
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathundecoratea void PathUndecorateA( LPSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "2d98ad60-8a7d-4b8d-9b5c-27e348bdc2c3")]
public static extern void PathUndecorate(StringBuilder pszPath);
///
/// Replaces certain folder names in a fully qualified path with their associated environment string.
///
///
/// Type: LPCTSTR
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be unexpanded.
///
///
/// Type: LPTSTR
///
/// A pointer to a buffer that, when this method returns successfully, receives the unexpanded string. The size of this buffer must
/// be set to MAX_PATH to ensure that it is large enough to hold the returned string.
///
///
///
/// Type: UINT
/// The size, in characters, in the pszBuf buffer.
///
///
/// Type: BOOL
/// Returns TRUE if successful; otherwise, FALSE.
///
///
/// The following folder paths are replaced by their equivalent environment string.
///
///
/// Folder
/// Environment String
///
/// -
/// The All Users profile folder
/// %ALLUSERSPROFILE%
///
/// -
/// The current user's application data folder (Windows Vista and later only).
/// %APPDATA%
///
/// -
/// The system name
/// %COMPUTERNAME%
///
/// -
/// The Program Files folder
/// %ProgramFiles%
///
/// -
/// The system root folder
/// %SystemRoot%
///
/// -
/// The system drive letter
/// %SystemDrive%
///
/// -
/// The current user's profile folder
/// %USERPROFILE%
///
///
///
/// Note %APPDATA% and %USERPROFILE% are relative to the user making the call. This function does not work if the user is
/// being impersonated from a service. For further discussion of access control issues, see Access Control.
///
///
/// The environment variables listed in the above table might not all be set on all systems. If an environment variable is not set,
/// it is not unexpanded.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathunexpandenvstringsa BOOL PathUnExpandEnvStringsA(
// LPCSTR pszPath, LPSTR pszBuf, UINT cchBuf );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "cfab1ee0-03f3-4e0f-a29d-5331fec022b5")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathUnExpandEnvStrings(string pszPath, StringBuilder pszBuf, uint cchBuf);
///
/// Removes the attributes from a folder that make it a system folder. This folder must actually exist in the file system.
///
///
/// Type: LPTSTR
///
/// A pointer to a null-terminated string of maximum length MAX_PATH that contains the name of an existing folder that will have the
/// system folder attributes removed.
///
///
///
/// Type: BOOL
/// Returns nonzero if successful, or zero otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathunmakesystemfoldera BOOL PathUnmakeSystemFolderA(
// LPCSTR pszPath );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "9c748ed6-3ee6-4889-8fdd-b33ed9d711d0")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathUnmakeSystemFolder(string pszPath);
///
/// Removes quotes from the beginning and end of a path.
///
///
/// Type: LPTSTR
///
/// A pointer to a null-terminated string of length MAX_PATH that contains the path. When the function returns successfully, points
/// to the string with beginning and ending quotation marks removed.
///
///
///
/// No return value.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathunquotespacesa BOOL PathUnquoteSpacesA( LPSTR lpsz );
[DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("shlwapi.h", MSDNShortId = "00474c95-ec59-489a-bee3-191b98a47567")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PathUnquoteSpaces(StringBuilder lpsz);
}
}