Check if a directory or file exists

xiaoxiao2021-03-06  43

You can find (Win32_find_data) to find (Win32_find_data) to find the file or folder, or use PathFileExists to judge. GetFileAttributes and PathiSDirectory can be used to determine if the file is a directory. Creating a file can be used with createDirectory or MakeSuredIRectoryPathexists.

Bool FileExists (CSTRING FILENAME)

{

Win32_find_data findfiledata;

Handle hfind;

Bool findflag = false;

Hfind = FindfirstFile (FileName, & FindFileData);

IF (hfind == invalid_handle_value) {findflag = false;} else {findflag = true;} findclose (hfind); Return Findflag;}

DWORD DWFLAG =

GetFileAttributes (Pathname);

IF (dwflag == 0xfffffffff)

// does not exist

...

IF (dwflag & file_attribute_directory &)

// is a folder ...

Else

// is the file

...

转载请注明原文地址:https://www.9cbs.com/read-67092.html

New Post(0)