suppress file creation
-
i'm just getting into programming and for one of my projects involves opening a file, but if it doesn't exist it is not supposed to create one, but rather output an error message. in some cases, if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this? any help would be much appreciated thanks -james jnerv
-
i'm just getting into programming and for one of my projects involves opening a file, but if it doesn't exist it is not supposed to create one, but rather output an error message. in some cases, if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this? any help would be much appreciated thanks -james jnerv
jnerv wrote:
most of the time it creates the file and doesn't output the message.
What function are you using? You may try
PathFileExists()
Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each. -
i'm just getting into programming and for one of my projects involves opening a file, but if it doesn't exist it is not supposed to create one, but rather output an error message. in some cases, if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this? any help would be much appreciated thanks -james jnerv
If you're using MFC CFile class if you will pass only CFile::modeRead it won't create it if it doesn't exist (Open function). If you're using fopen pass only 'r' to mode parameter and the function will fail if the file does not exist.
-
i'm just getting into programming and for one of my projects involves opening a file, but if it doesn't exist it is not supposed to create one, but rather output an error message. in some cases, if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this? any help would be much appreciated thanks -james jnerv
-
i'm just getting into programming and for one of my projects involves opening a file, but if it doesn't exist it is not supposed to create one, but rather output an error message. in some cases, if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this? any help would be much appreciated thanks -james jnerv
-
i'm just getting into programming and for one of my projects involves opening a file, but if it doesn't exist it is not supposed to create one, but rather output an error message. in some cases, if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this? any help would be much appreciated thanks -james jnerv
Another way for you knowledge:- You can also use CFile::GetFileStatus(CString filename,CFileStatus status) a static function returns false if it doesnt exist and then return from your function. Regards farPointer
-
i'm just getting into programming and for one of my projects involves opening a file, but if it doesn't exist it is not supposed to create one, but rather output an error message. in some cases, if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this? any help would be much appreciated thanks -james jnerv
jnerv wrote:
if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this?
Which Api/Class are you using to read/write File.. as these api contain flags... which can return ERRROR is no file Exist by that name on the specified path.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV