CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    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
    
    		}
    	}
    }
    mpliam

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Feb 2005
    Location
    Madrid (Spain)
    Posts
    511

    Re: Can CFileDialog (FALSE) detect an existing file?

    Other way: use

    Code:
    BOOL PathFileExists(      
        LPCTSTR pszPath
    );
    to know if the file exists.

    Regards!

  4. #4
    Join Date
    May 2002
    Posts
    1,798

    Re: Can CFileDialog (FALSE) detect an existing file?

    OFN_OVERWRITEPROMPT works. thanks. I should have looked up the flags myself.
    mpliam

  5. #5
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    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?
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured