Discussion:
file existence
(too old to reply)
didan
2008-06-10 15:22:13 UTC
Permalink
is there any way to check whether a certain file exists without
using fopen ?
Thanks for help
Ed Mulroy [TeamB]
2008-06-10 15:47:08 UTC
Permalink
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
Post by didan
is there any way to check whether a certain file exists without
using fopen ?
Thanks for help
Tom420
2008-07-27 06:32:03 UTC
Permalink
Post by didan
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...");
}

Loading...