APIS for file path operations in Shell

Source: Internet
Author: User

In the past, when I was writing code, I encountered a problem with the file path. for example, extract the directory or file name of the file path and determine whether the directory or file exists. every time you encounter such a problem, you always have to write your own code to implement it. Extracting directories involves tedious string analysis operations. To detect whether directories/files exist, you can determine whether directories/files can be opened. When the level is not enough, of course, the more you write, the more hidden bugs there will be. recently, when I looked at some code collected on the internet, I found some useful shell APIs to implement some of the functions I needed. So I looked at msdn and found that I had been behind closed doors for so long. the following describes some shell APIs for file operations.

Prototype: bool pathfileexists (lpctstr pszpath );

Function: determines whether the directory/file specified by pszpath exists.

 

Prototype: bool pathisdirectory (lpctstr pszpath );

Function: determines whether the path specified by pszpath is a directory.

 

Prototype: bool pathisdirectoryempty (lpctstr pszpath );

Function: determines whether the directory specified by pszpath is an empty directory.

 

Prototype: bool pathremovefilespec (lptstr pszpath );

Function: remove the file name and backslash (if any) at the end of the path specified by pszpath)

Example:

Tchar szpath [] = _ T ("d :\\ fantasy novels \ ridiculous ");

If (: pathremovefilespec (szpath ))
{
// Szpath value: D: \ fantasy novel
}

 

Prototype: void pathstrippath (lptstrPszpath);

Function: remove the directory file in the path specified by pszpath.

Example:

Tchar szpath [] = _ T ("d :\\ fantasy novels \ ridiculous ");

: Pathstrippath (szpath );
// The szpath value is

 

Prototype: bool pathisroot (lpctstr pszpath );

Function: determines whether the path specified by pszpath is the root directory (that is, the volume label)

 

Prototype: bool pathissameroot (lpctstr pszpath1, lpctstr pszpath2 );

Function: determines whether the path specified by pszpath1 and pszpath2 are in the same root directory.

 

Prototype: bool pathstriptoroot (lptstr szrot );

Function: Remove directories other than the root directory in szrot.

 

Prototype: lptstr pathskiproot (lpctstr pszpath );

Function: determines other parts of the pszpath except the root directory.

 

Prototype: int pathisexe (lpcwstr szfile );

Function: determines whether the file specified by szfile is an executable file.

 

Prototype: bool pathisurl (lpctstr pszpath );

Function: determines whether the path specified by pszpath is in URL format.

 

There are also a lot of such APIs, ah, I am too class, don't get it. Anyway, when I need similar functions, I will first check the functions provided in shell, instead of building a car behind closed doors.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.