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. Check if file existe, get temporary file name?

Check if file existe, get temporary file name?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 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.
  • T Offline
    T Offline
    TPN
    wrote on last edited by
    #1

    How to check if file existe (not by trying to open it, fail : not existe or not) How to get the temporary file name which is not coincide with existing files.

    H M D L 4 Replies Last reply
    0
    • T TPN

      How to check if file existe (not by trying to open it, fail : not existe or not) How to get the temporary file name which is not coincide with existing files.

      H Offline
      H Offline
      Hari Krishnan Noida
      wrote on last edited by
      #2

      Hi, 1. Check File exists CFileFind chkFileExistence; if(chkFileExistence.FindFile(strFileName)) { //File exists }else{ //File does not exists } 2. Creating Temporary File Name You can use different methods to create a temporary file name. My suggestion, try to create a file name with Date & Time. Hope this helps. regards ~Hari~

      T 1 Reply Last reply
      0
      • H Hari Krishnan Noida

        Hi, 1. Check File exists CFileFind chkFileExistence; if(chkFileExistence.FindFile(strFileName)) { //File exists }else{ //File does not exists } 2. Creating Temporary File Name You can use different methods to create a temporary file name. My suggestion, try to create a file name with Date & Time. Hope this helps. regards ~Hari~

        T Offline
        T Offline
        TPN
        wrote on last edited by
        #3

        Any more question : How to check if file existe in VB? Thank you for your fast reply.

        1 Reply Last reply
        0
        • T TPN

          How to check if file existe (not by trying to open it, fail : not existe or not) How to get the temporary file name which is not coincide with existing files.

          M Offline
          M Offline
          MAAK
          wrote on last edited by
          #4

          to check if a file exist you can use the shell function

          BOOL PathFileExists(
              LPCTSTR pszPath
              );
          

          it takes the file path and return 1 if it exist and 0 if not for temporary files, there is the function

          UINT GetTempFileName(
            LPCTSTR lpPathName,      // directory name
            LPCTSTR lpPrefixString,  // file name prefix, first three letters is taken only
            UINT uUnique,            // integer
            LPTSTR lpTempFileName    // file name buffer
          );
          

          which can be used to generate temporary file names. The temporary path is formed like this lpPathName+'\'+lpPrefixString+[uUnique as hexadecimal] + ".tmp" and returned in the lpTempFileName for e.g if the path is c:\ and the unique integer is 10 and the prefix is "fil" the result will be c:\fil000A.tmp. The uUnique parameter should have a unique integer value but if you passed 0 the system will assign this unique value.

          T 1 Reply Last reply
          0
          • M MAAK

            to check if a file exist you can use the shell function

            BOOL PathFileExists(
                LPCTSTR pszPath
                );
            

            it takes the file path and return 1 if it exist and 0 if not for temporary files, there is the function

            UINT GetTempFileName(
              LPCTSTR lpPathName,      // directory name
              LPCTSTR lpPrefixString,  // file name prefix, first three letters is taken only
              UINT uUnique,            // integer
              LPTSTR lpTempFileName    // file name buffer
            );
            

            which can be used to generate temporary file names. The temporary path is formed like this lpPathName+'\'+lpPrefixString+[uUnique as hexadecimal] + ".tmp" and returned in the lpTempFileName for e.g if the path is c:\ and the unique integer is 10 and the prefix is "fil" the result will be c:\fil000A.tmp. The uUnique parameter should have a unique integer value but if you passed 0 the system will assign this unique value.

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

            Thanks so much. That is all I need.

            1 Reply Last reply
            0
            • T TPN

              How to check if file existe (not by trying to open it, fail : not existe or not) How to get the temporary file name which is not coincide with existing files.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              TPN wrote: How to check if file existe (not by trying to open it, fail : not existe or not) You can use _access() or CFile::GetStatus(). TPN wrote: How to get the temporary file name which is not coincide with existing files. Use GetTempFileName().

              1 Reply Last reply
              0
              • T TPN

                How to check if file existe (not by trying to open it, fail : not existe or not) How to get the temporary file name which is not coincide with existing files.

                L Offline
                L Offline
                lob
                wrote on last edited by
                #7

                Here's how you check if file exists : CFileFind fileCheckExistance; CString strPath = "C:\\Test\\myfile.exe"; if ( fileCheckExistance.FindFile( strPath ) ) AfxMessageBox("File exists !"); else AfxMessageBox("File doesnt exist.");

                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