Board index » cppbuilder » file existence

file existence


2008-06-10 11:22:13 PM
cppbuilder42
is there any way to check whether a certain file exists without
using fopen ?
Thanks for help
 
 

Re:file existence

The Windows API function GetFileAttributes can do that.
Code to use it could look something like this:
-------------------
#include <windows.h>
const DWORD NOT_FOUND = 0xFFFFFFFF;
DWORD attribs = GetFileAttributes(file_name_char_str);
if (attribs != NOT_FOUND) // if a file or dir of that name exists
{
if (attribs & FILE_ATTRIBUTE_DIRECTORY)
// it is a directory
else
// it is a file
}
-------------------
. Ed
Quote
didan wrote in message
news:484e9c25$ XXXX@XXXXX.COM ...

is there any way to check whether a certain file exists without
using fopen ?
Thanks for help
 

Re:file existence

didan wrote:
Quote
is there any way to check whether a certain file exists without
using fopen ?
Thanks for help
FileExists() from SysUtils
if(FileExists("C:\\myfile.txt"))
{
ShowMessage("Got it!");
}
else
{
ShowMessage("Entering panic mode...");
}
 

{smallsort}