Fopen returns a cause code 2 but the file exists in the directory.

This is a discussion on Fopen returns a cause code 2 but the file exists in the directory. within the C++ Programming forums, part of the General Programming Boards category; I get the fact that the cause code value of 2 is for the file not found. All I do ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    1

    Fopen returns a cause code 2 but the file exists in the directory.

    I get the fact that the cause code value of 2 is for the file not found.

    All I do is just read the file and open to see if its readable.

    I am pasting below a piece of code.
    Code:
    BOOL bReadFile( BYTE* p, INT32& nSize, CString strFilename)
    {
    	CFile			cfSessionFile;
    	CFileException	ex;
    
    	if (cfSessionFile.Open( strFilename, CFile::modeRead, &ex))
    	{
    		nSize = (INT32) cfSessionFile.GetLength();
    
    		if((p != NULL) && (nSize > 0))
    		{
    			cfSessionFile.Read( p, nSize);
    		}
    		cfSessionFile.Close();
    	}
    	else
                           {  m_ologging.writelogmessage("failed to open the file with cause =%d",ex.m_cause);
    		return FALSE;
                            }
    
    	return TRUE;
    }
    I am not sure why should the open fail when we try to open just the file in the read only mode. The application is a multi threading environment. I have run out of ideas as the file does exist, i am tryong to open the gzip files. This does not happen always that the read of this fails.

    I would be really happy if i could get any help on it.

    Cheers,
    Rajesh.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Print or look at the value of strFilename in the debugger and see if the filename looks correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21