-
February 24th, 2005, 10:39 AM
#1
How I can check file for existance?
-
February 24th, 2005, 10:45 AM
#2
Re: How I can check file for existance?
Code:
CFileStatus status;
if (CFile::GetStatus(filename, status))
{
// file exists
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
Please remember to rate useful answers. It lets us know when a question has been answered.
-
February 24th, 2005, 10:48 AM
#3
Re: How I can check file for existance?
10x, Roger
also FindFirstFile
sorry for sore dull ques...
-
February 24th, 2005, 10:56 AM
#4
Re: How I can check file for existance?
This question has been asked countless times. You should do a search before posting question.
-
February 24th, 2005, 12:33 PM
#5
Re: How I can check file for existance?
You can also check for a file existance or a folder existence like that:
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA fileFound;
// Search for the specified file
hFind = FindFirstFile(filePath, &fileFound);
// if file to be copied exists
if (!(hFind == INVALID_HANDLE_VALUE))
{
// Do something here
}
I hope it helps!
Poka!
-
February 24th, 2005, 03:57 PM
#6
Re: How I can check file for existance?
I prefer to use GetFileAttributes to check the existence of a file.
And cilu's absolutely correct: you should always search CG and Google well before you post.
Best Regards,
--Zim If you find this post useful, please rate it.
_________________________________
"Have you the brain worms?!?!?"
-
February 24th, 2005, 04:36 PM
#7
Re: How I can check file for existance?
Code:
CString szPath("c:\\windows");
CString szFile("c:\\test.txt");
DWORD dwAttr = GetFileAttributes(szPath);
if(dwAttr == 0xffffffff)
{
DWORD dwError = GetLastError();
if(dwError == ERROR_FILE_NOT_FOUND)
{
// file not found
}
else if(dwError == ERROR_PATH_NOT_FOUND)
{
// path not found
}
else if(dwError == ERROR_ACCESS_DENIED)
{
// file or directory exists, but access is denied
}
else
{
// some other error has occured
}
}
else
{
if(dwAttr & FILE_ATTRIBUTE_DIRECTORY)
{
// this is a directory
if(dwAttr & FILE_ATTRIBUTE_ARCHIVE)
// Directory is archive file
if(dwAttr & FILE_ATTRIBUTE_COMPRESSED)
// Directory is compressed
if(dwAttr & FILE_ATTRIBUTE_ENCRYPTED)
// Directory is encrypted
if(dwAttr & FILE_ATTRIBUTE_HIDDEN)
// Directory is hidden
if(dwAttr & FILE_ATTRIBUTE_READONLY)
// Directory is read-only
if(dwAttr & FILE_ATTRIBUTE_REPARSE_POINT)
// Directory has an associated reparse point
if(dwAttr & FILE_ATTRIBUTE_SYSTEM)
// Directory is part or used exclusively by the operating system
}
else
{
// this is an ordinary file
if(dwAttr & FILE_ATTRIBUTE_ARCHIVE)
// File is archive file
if(dwAttr & FILE_ATTRIBUTE_COMPRESSED)
// File is compressed
if(dwAttr & FILE_ATTRIBUTE_ENCRYPTED)
// File is encrypted
if(dwAttr & FILE_ATTRIBUTE_HIDDEN)
// File is hidden
if(dwAttr & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)
// File will not be indexed
if(dwAttr & FILE_ATTRIBUTE_OFFLINE)
// Data of file is not immediately available
if(dwAttr & FILE_ATTRIBUTE_READONLY)
// File is read-only
if(dwAttr & FILE_ATTRIBUTE_REPARSE_POINT)
// File has an associated reparse point
if(dwAttr & FILE_ATTRIBUTE_SPARSE_FILE)
// File is a sparse file
if(dwAttr & FILE_ATTRIBUTE_SYSTEM)
// File is part or used exclusively by the operating system
if(dwAttr & FILE_ATTRIBUTE_TEMPORARY)
// File is being used for temporary storage
}
}
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
|