Click to See Complete Forum and Search --> : file exists
BrianEKeating
September 27th, 2001, 09:55 AM
to determin if a file exists !
do i have to try and open the file and see if it is successfully opened for read! or is there a command to do it?
cheers
b
Of course I do it for the ratings!
Igor Soukhov
September 27th, 2001, 02:00 PM
Hi ! Hope this function will usefull for you.
#include <fstream>
bool FileExists (const char *fname)
{
return std::ifstream(fname) != NULL;
}
Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor@soukhov.com | ICQ:57404554 | http://soukhov.com
Member of Russian Software Developer Network http://rsdn.ru
Axter
September 27th, 2001, 03:47 PM
You don't have to open it. You can use the stat function.
Example:
#include <sys/types.h>
#include <sys/stat.h>
struct stat f__stat;
bool FileExist = (stat(lpFileName,&f__stat) != 0)
Although stat() is a non-Ansi C++ function, most compilers support it.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.