几个关于文件路径方面的函数,不断更新...

PathStripToRoot      得到该路径的根目录

 

Removes all parts of the path except for the root information.

Syntax

BOOL PathStripToRoot(      

    LPTSTR szRoot


);

Parameters

szRoot
[in, out] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be converted.

Return Value

Returns TRUE if a valid drive letter was found in the path, or FALSE otherwise.

 

 

 

PathIsDirectory              查看路径是否是一个合法的文件夹

Verifies that a path is a valid directory.

Syntax

BOOL PathIsDirectory(      
    LPCTSTR pszPath
);

Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to verify.

Return Value

Returns TRUE if the path is a valid directory, or FALSE otherwise.

 

 

GetDiskFreeSpaceEx Function  得到某个盘的使用未使用容量

 

Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.

BOOL WINAPI GetDiskFreeSpaceEx(
__in LPCTSTR lpDirectoryName ,
__out PULARGE_INTEGER lpFreeBytesAvailable ,
__out PULARGE_INTEGER lpTotalNumberOfBytes ,
__out PULARGE_INTEGER lpTotalNumberOfFreeBytes
);

Parameters

lpDirectoryName

A directory on the disk.

If this parameter is NULL, the function uses the root of the current disk.

If this parameter is a UNC name, it must include a trailing backslash, for example, //MyServer/MyShare/.

This parameter does not have to specify the root directory on a disk. The function accepts any directory on a disk.

The calling application must have FILE_LIST_DIRECTORY access rights for this directory.

lpFreeBytesAvailable

A pointer to a variable that receives the total number of free bytes on a disk that are available to the user who is associated with the calling thread.

This parameter can be NULL.

If per-user quotas are being used, this value may be less than the total number of free bytes on a disk.

lpTotalNumberOfBytes

A pointer to a variable that receives the total number of bytes on a disk that are available to the user who is associated with the calling thread.

This parameter can be NULL.

If per-user quotas are being used, this value may be less than the total number of bytes on a disk.

To determine the total number of bytes on a disk or volume, use IOCTL_DISK_GET_LENGTH_INFO .

lpTotalNumberOfFreeBytes

A pointer to a variable that receives the total number of free bytes on a disk.

This parameter can be NULL.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero (0). To get extended error information, call GetLastError .

Remarks

The values obtained by this function are of the type ULARGE_INTEGER . Do not truncate these values to 32 bits.

The GetDiskFreeSpaceEx function returns zero (0) for lpTotalNumberOfFreeBytes and lpFreeBytesAvailable for all CD requests unless the disk is an unwritten CD in a CD-RW drive.

Symbolic link behavior—If the path points to a symbolic link, the operation is performed on the target.

 

 

GetDriveType Function 得到盘的类型

 

Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive.

To determine whether a drive is a USB-type drive, call SetupDiGetDeviceRegistryProperty and specify the SPDRP_REMOVAL_POLICY property.

UINT WINAPI GetDriveType(
__in LPCTSTR lpRootPathName
);

Parameters

lpRootPathName

The root directory for the drive.

A trailing backslash is required. If this parameter is NULL, the function uses the root of the current directory.

Return Value

The return value specifies the type of drive, which can be one of the following values.

 

 

 

 

PathAddBackslash Function


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.

Syntax

LPTSTR PathAddBackslash(      
    LPTSTR lpszPath
);

Parameters

lpszPath
[in, out] A pointer to a buffer with a string that represents a path. The size of this buffer should be set to MAX_PATH to ensure that it is large enough to hold the returned string.

Return Value

Returns the address of the NULL that terminates the string. If the backslash could not be appended due to inadequate buffer size, returns NULL.

 

PathAddExtension Function


Adds a file extension to a path string.

Syntax

BOOL PathAddExtension(      
    LPTSTR pszPath ,
    LPCTSTR pszExtension
);

Parameters

pszPath
[in, out] A pointer to a buffer with the null-terminated string to which the file extension will be appended. You should set the size of this buffer to MAX_PATH to ensure that it is large enough to hold the returned string.
pszExtension
[in] A pointer to a null-terminated string that contains the file extension.

Return Value

Returns TRUE if an extension was added, or FALSE otherwise.

PathFileExists Function


Determines whether a path to a file system object such as a file or directory is valid.

Syntax

BOOL PathFileExists(      
    LPCTSTR pszPath
);

Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the full path of the object to verify.

Return Value

Returns TRUE if the file exists, or FALSE otherwise. Call GetLastError for extended error information.

Remarks

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.

 

PathIsDirectoryEmpty Function


Determines whether a specified path is an empty directory.

Syntax

BOOL PathIsDirectoryEmpty(      
    LPCTSTR pszPath
);

Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be tested.

Return Value

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 "..".

Remarks

"C:/" is considered a directory.

 

PathIsPrefix Function


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://", ".", "..", "..//".

Syntax

BOOL PathIsPrefix(      
    IN LPCTSTR pszPrefix ,
    IN LPCTSTR pszPath
);

Parameters

pszPrefix
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the prefix for which to search.
pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be searched.

Return Value

Returns TRUE if the compared path is the full prefix for the path, or FALSE otherwise.

 

PathIsRoot Function


Parses a path to determine if it is a directory root.

Syntax

BOOL PathIsRoot(      
    LPCTSTR pPath
);

Parameters

pPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to be validated.

Return Value

Returns TRUE if the specified path is a root, or FALSE otherwise.

Remarks

Returns TRUE for paths such as "/", " X :/", "// server / share ", or "// server /". Paths such as "../path2" will return FALSE.

 

PathIsSameRoot Function


Compares two paths to determine if they have a common root component.

Syntax

BOOL PathIsSameRoot(      
    LPCTSTR pszPath1 ,
    LPCTSTR pszPath2
);

Parameters

pszPath1
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the first path to be compared.
pszPath2
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the second path to be compared.

Return Value

Returns TRUE if both strings have the same root component, or FALSE otherwise.

 

PathIsNetworkPath Function


Determines whether a path string represents a network resource.

Syntax

BOOL PathIsNetworkPath(      
    LPCTSTR pszPath
);

Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path.

Return Value

Returns TRUE if the string represents a network resource, or FALSE otherwise.

Remarks

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.

 

PathIsURL Function


Tests a given string to determine if it conforms to a valid URL format.

Syntax

BOOL PathIsURL(      
    LPCTSTR pszPath
);

Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the URL path to validate.

Return Value

Returns TRUE if pszPath has a valid URL format, or FALSE otherwise.

Remarks

This function does not verify that the path points to an existing site—only that it has a valid URL format.

 

 

 

 

PathSkipRoot Function


Parses a path, ignoring the drive letter or Universal Naming Convention (UNC) server/share path parts.

Syntax

LPCTSTR PathSkipRoot(      
    LPCTSTR pszPath
);

Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to parse.

Return Value

Returns the address of the beginning of the subpath that follows the root (drive letter or UNC server/share).

PathStripPath Function


Removes the path portion of a fully qualified path and file.

Syntax

void PathStripPath(      
    LPTSTR pszPath
);

Parameters

pszPath
[in, out] A pointer to a null-terminated string of maximum length MAX_PATH that contains the path and file name that will have the path portion removed.

Return Value

No return value.

PathMakeSystemFolder Function


Gives an existing folder the proper attributes to become a system folder.

Syntax

BOOL PathMakeSystemFolder(      
    LPTSTR pszPath
);

Parameters

pszPath
[in] A pointer to a null-terminated string of maximum length MAX_PATH that contains the name of an existing folder that will be made into a system folder.

Return Value

Returns nonzero if successful, or zero otherwise.

 

PathUnmakeSystemFolder Function


Removes the attributes from a folder that make it a system folder. This folder must actually exist in the file system.

Syntax

BOOL PathUnmakeSystemFolder(      
    LPTSTR pszPath
);

Parameters

pszPath
[in] 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.

Return Value

Returns nonzero if successful, or zero otherwise.

 

PathIsSystemFolder Function


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.

Syntax

BOOL PathIsSystemFolder(      
    LPCTSTR pszPath ,
    DWORD dwAttrb
);

Parameters

pszPath
[in] 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.
dwAttrb
[in] The file attributes to be compared. If pszPath is not NULL, this value is ignored. If pszPath is NULL, 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.

Return Value

Returns nonzero if the pszPath or dwAttrb represent a system folder, or zero otherwise.

 

 

暂时就写这么多吧。大家可以在  shlwapi.h 这个文件里面找到大部分的函数。  如果以后还有会加的。

 

 

 

 

 

 

 

 


你可能感兴趣的:(attributes,path,string,function,system,network)