Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. suppress file creation

suppress file creation

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jnerv
    wrote on last edited by
    #1

    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

    R A J G F 6 Replies Last reply
    0
    • J 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

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J 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

        A Offline
        A Offline
        Alex Orovetskiy
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • J 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

          J Offline
          J Offline
          jnerv
          wrote on last edited by
          #4

          right on, thanks for the help guys. saved me another day of tearing my hair out, haha. muchas gracias later -james

          1 Reply Last reply
          0
          • J 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

            G Offline
            G Offline
            gamitech
            wrote on last edited by
            #5

            if u use CreateFile() Specifiy the create dispozition paramater: OPEN_EXISTING; if the function return INVALID_HANDLE_VALUE then it does not exist or u can use GetLastError() and FormatMessage() to see the exact error returned :) hope this helps gabby

            1 Reply Last reply
            0
            • J 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

              F Offline
              F Offline
              FarPointer
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • J 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

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups