A/C + + determines if a file/folder exists

Source: Internet
Author: User

First, determine whether the folder exists:
1. Use CreateDirectory (".//filemanege", NULL), or create if the folder Filemanege does not exist.
2. Or if (_access (".//filemanege", 0) ==-1), indicates that Filemanege does not exist.
3. or bool Pathisdirectory (LPCTSTR Pszpath);

Second, determine whether the file exists:
1. Using if ((File=fopen (".//filemanege//f//f.dat", "RB")) ==null)
File=fopen (".//filemanege//f//f.dat", "ab+"); First judge whether there is no file, no words to create a new
2. Use if (_access (".//filemanege//f//f.dat", 0) ==-1) to indicate that the file does not exist.


function int _access (const char *path, int mode), can determine the Mode property of a file or folder
Mode=00;//existence only
Mode=02;//write permission
Mode=04;//read permission
Mode=06;//read and Write permission
Need to include header file <io.h>.

Transferred from: http://luzongping1986.blog.163.com/blog/static/788129152009379452504/

A/C + + determines if a file/folder exists

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.