-
July 1st, 2001, 08:37 AM
#1
how to detect if a file has been already created?
I've got a path, say c:\mypath\myfile.txt . I 'd like to find out if myfile.txt already exists in that location. How to do that?
-
July 1st, 2001, 09:05 AM
#2
Re: how to detect if a file has been already created?
CString fname("test.txt");
int exist = GetFileAttributes(fname);
if (exist == -1)
{
MessageBox(fname,"file does not exist",MB_ICONEXCLAMATION);
}
else
{
MessageBox(fname,"file exists",MB_ICONEXCLAMATION);
}
or another method :
CStdioFile myFile;
CString sFileName = "c:\\test.txt";
CFileStatus stat;
if( !myFile.GetStatus(sFileName, stat))
{
MessageBox("file does not exists");
}
-
July 1st, 2001, 09:06 AM
#3
Re: how to detect if a file has been already created?
use _access(FileName,0)
Rating isn't important...But gurus respect it and keep high
-
July 1st, 2001, 10:13 AM
#4
Re: how to detect if a file has been already created?
And the REAL "C++" (question was posted under "C++" category =) solution:
#include <fstream>
using std::ifstream;
ifstream file("C:\\path\\filename.ext");
if (file)
{
//file exists
}
else
{
//file not exists
}
Rate answer if it help 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|