Can CFileDialog (FALSE) detect an existing file?
I have overridden OnFileSave and used CFileDialog to implement the process. It would be useful if the dialog would warn the user if a file of that name already exists, offering an option to replace it. But my overridden implementation doesnt do that. It will simply overwrite the file if it exists. (very unprofessional).
Is there a flag or something that can be set using CFileDialog that will warn if file exists?
Here's the code I've been using:
Code:
void myDlg::OnFileSaveas()
{
const char fileDialogFilter[] =
"Data Files (*.dat)|*.dat||";
const char fileDialogExt[] = "dat";
CFileDialog fileDialog(FALSE,
fileDialogExt, m_csFilename,
OFN_FILEMUSTEXIST, fileDialogFilter);
if (fileDialog.DoModal() == IDOK)
{
CWaitCursor wait;
if(fileDialog.GetFileExt()=="dat")
{
m_csPathname = fileDialog.GetPathName();
m_csFilename = fileDialog.GetFileName();
//.. do the save
}
}
}
Re: Can CFileDialog (FALSE) detect an existing file?
OFN_OVERWRITEPROMPT should prompt the user for overwriting.
You can find all the flags here: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx.
Re: Can CFileDialog (FALSE) detect an existing file?
Other way: use
Code:
BOOL PathFileExists(
LPCTSTR pszPath
);
to know if the file exists.
Regards!
Re: Can CFileDialog (FALSE) detect an existing file?
OFN_OVERWRITEPROMPT works. thanks. I should have looked up the flags myself.
Re: Can CFileDialog (FALSE) detect an existing file?
OFN_FILEMUSTEXIST is not needed for Save dialog. It is ignored.
What would it mean if you require that file must exist before saving? ;)