Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
This mornning i face new problem while dealing with my file manipulation software.
I'm currently working on file manupulation utility which take 13 CSV (Comma saparators of EXCEL) files as input file and manupulates to create output file.

MY QUASTION:-

HOW I'M GOING TO KNOWN IS FILE IS OPEN OR NOT?

If i used Open function like below,
C++
if(!MyTestFile.Open("ABC.csv",CFile:ModeRead)
{
    MyTestFile.Close();
}

but it work if file failed to open
not if file open success fully

REQUIREMENT:-
Now if i want to close a file.if file not open then close give me assertion but before i used Close() i must check whether file already open or not something like given algorithm

Check file is OPEN //Want fucnction to do so,
IF File is OPEN
Close File
ELSE
Continue


_____________________________________________________________________
ALL RELATED HELPS,LINKS,CODE BLOCK,CODES ARE MOST WELCOME
Posted

try to use a try catch. I haven't tried it here since I unistalled my IDE. But do try it.
 
Share this answer
 
Comments
Coder Block 31-Aug-11 1:17am    
my application in try catch but it gives me assertion first then catch message
C#
if(!MyTestFile.Open("ABC.csv",CFile:ModeRead)
{
    //do not close your file when you fail to open it
    //MyTestFile.Close();
}

//if you can get here, you can do something
............
//and then you can close your file
     MyTestFile.Close();
 
Share this answer
 
Comments
Coder Block 31-Aug-11 2:55am    
That exactly i doesn't want

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900