Click to See Complete Forum and Search --> : File opened, or created?
MrDoomMaster
March 19th, 2006, 07:21 PM
using the function _tsopen_s() with the _CREAT flag, I want to be able to tell if the file was created or opened. This would be useful for determining if I must set default settings in an INI file, for example.
Currently I do the following check:
if(!_filelength(mFile))
mCreated = true;
This actually lies, because if the file was OPENED but was originally 0 bytes in length, it wouldn't have been created.
I want to use a more "solid" method of achieving my goal. Any suggestions? Thanks.
Brenton S.
March 19th, 2006, 08:19 PM
I don't understand what you're trying to do. Can you be more specific?
MrDoomMaster
March 19th, 2006, 10:26 PM
When you specify the _CREAT flag, the file is created if it doesn't exist and then it is opened. If the file exists, it is opened.
I want to be able to tell when the file is created, or in other words, I want to know if the file didn't exist when I tried to open it. I apologize for any insufficient information.
Kheun
March 19th, 2006, 10:36 PM
You can use _stat() to check the status of the file before opening it.
golanshahar
March 20th, 2006, 02:22 AM
When you specify the _CREAT flag, the file is created if it doesn't exist and then it is opened. If the file exists, it is opened.
I want to be able to tell when the file is created, or in other words, I want to know if the file didn't exist when I tried to open it. I apologize for any insufficient information.
Before opening the file you can call ::PathFileExists() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/path/pathfileexists.asp) to determine if the file exists or not ;)
Cheers
NoHero
March 20th, 2006, 03:10 AM
Or receive the file time... or... or... or... There are so many ways..
MrDoomMaster
March 20th, 2006, 11:08 AM
You know, most of the time I ask a question I'm usually given the most obvious answers. This, in turn, makes me feel stupid because it was so trivial :) I should have known this, really... I don't know what's wrong with me sometimes lol.
Thanks a bunch guys!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.