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. Returning a file name

Returning a file name

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 5 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.
  • R Offline
    R Offline
    RalfPeter
    wrote on last edited by
    #1

    How can I check for the existence of a file in a directory? I need to check it before overwriting the file. Thx, Ralf. ralf.riedel@usm.edu

    D C R T 4 Replies Last reply
    0
    • R RalfPeter

      How can I check for the existence of a file in a directory? I need to check it before overwriting the file. Thx, Ralf. ralf.riedel@usm.edu

      D Offline
      D Offline
      Dave Bryant
      wrote on last edited by
      #2

      Try PathFileExists(), declared in shlwapi.h. You need to link with shlwapi.lib. Dave

      1 Reply Last reply
      0
      • R RalfPeter

        How can I check for the existence of a file in a directory? I need to check it before overwriting the file. Thx, Ralf. ralf.riedel@usm.edu

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        #include < io.h > if (_access(filename, 0) == 0) { the file exists } -c


        Image tools: ThumbNailer, Bobber, TIFFAssembler

        1 Reply Last reply
        0
        • R RalfPeter

          How can I check for the existence of a file in a directory? I need to check it before overwriting the file. Thx, Ralf. ralf.riedel@usm.edu

          R Offline
          R Offline
          Rob Groves
          wrote on last edited by
          #4

          RalfPeter wrote: How can I check for the existence of a file in a directory? I need to check it before overwriting the file. Thx, Ralf. Windows, C runtime versions already submitted, but if you are addicted to MFC try the following...

          BOOL FileUtil::FileExists(const CString& strFile)
          {
          CFileStatus fs;
          if (!CFile::GetStatus(strFile, fs))
          return FALSE;
          else
          return TRUE;
          }

          1 Reply Last reply
          0
          • R RalfPeter

            How can I check for the existence of a file in a directory? I need to check it before overwriting the file. Thx, Ralf. ralf.riedel@usm.edu

            T Offline
            T Offline
            TomKat
            wrote on last edited by
            #5

            i can`t believe these answers ! check this out : you can use relative or full path ! unsigned long FileSize(const char *fullpath) { _finddata_t data; long handle=0; handle=_findfirst(fullpath,&data); if(handle==-1) return -1; _findclose(handle); if(data.attrib & _A_SUBDIR) { return -1; } return data.size; } BOOL FileExists(const char *fullpath) { _finddata_t data; long handle=0; handle=_findfirst(fullpath,&data); if(handle==-1) return 0; _findclose(handle); if(data.attrib & _A_SUBDIR) { return 0; } return 1; } //be cool I am the mighty keeper of the book on knowledge . Contact me to get your copy .

            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