subj???
Printable View
subj???
Code:CFileStatus status;
if (CFile::GetStatus(filename, status))
{
// file exists
10x, Roger
also FindFirstFile
sorry for sore dull ques...
This question has been asked countless times. You should do a search before posting question.
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!
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. :thumb:
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
}
}