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. File handling issue

File handling issue

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelp
13 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.
  • _ __yash__

    CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead); In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC application

    W Offline
    W Offline
    Waldermort
    wrote on last edited by
    #3

    yashveer wrote:

    In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"??

    Err, saptxt.Open("C:\My folder\temp_170807.txt",CFile::modeRead); or am I missing something here?

    S 1 Reply Last reply
    0
    • W Waldermort

      yashveer wrote:

      In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"??

      Err, saptxt.Open("C:\My folder\temp_170807.txt",CFile::modeRead); or am I missing something here?

      S Offline
      S Offline
      SnaKeBeD
      wrote on last edited by
      #4

      hi, please mention the complete error... also,change the line to saptext.Open("C:\\My folder\\temp_170807.txt",CFile::modeRead); note the slashes...

      swaroop

      _ 1 Reply Last reply
      0
      • _ __yash__

        CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead); In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC application

        _ Offline
        _ Offline
        __yash__
        wrote on last edited by
        #5

        Well thanks Swathee i was putting single back-slash"\" double back-slash solved the problem...thnks[:)] but the problem of temp_*.txt still remains what can i do to get rid of this problem?? Program doesnt take temp_*.txt

        S 1 Reply Last reply
        0
        • S SnaKeBeD

          hi, please mention the complete error... also,change the line to saptext.Open("C:\\My folder\\temp_170807.txt",CFile::modeRead); note the slashes...

          swaroop

          _ Offline
          _ Offline
          __yash__
          wrote on last edited by
          #6

          hi swaroop double back-slash solved that problem... In the location C:\Myfolder i could have, lets say: temp_170807.txt temp_180807.txt, etc.... But only one file at a time will be present so i need to give a generic criteria like: C:\\My folder\\temp_*.txt Hope you got the problem

          S 1 Reply Last reply
          0
          • _ __yash__

            Well thanks Swathee i was putting single back-slash"\" double back-slash solved the problem...thnks[:)] but the problem of temp_*.txt still remains what can i do to get rid of this problem?? Program doesnt take temp_*.txt

            S Offline
            S Offline
            sw thi
            wrote on last edited by
            #7

            What are you trying to do exactly?? you have to open files separately you can't open them in a bunch.

            "What's on your mind, if you will allow the overstatement?"

            _ 1 Reply Last reply
            0
            • S sw thi

              What are you trying to do exactly?? you have to open files separately you can't open them in a bunch.

              "What's on your mind, if you will allow the overstatement?"

              _ Offline
              _ Offline
              __yash__
              wrote on last edited by
              #8

              i m opening only one file at a time.... only one file at any given time will be present in the folder: C:\\My folder\\ i.e. i have either text_1000.txt or text_1001.txt in that location so i need to give something like text_*.txt i hope its clear...

              S 1 Reply Last reply
              0
              • _ __yash__

                hi swaroop double back-slash solved that problem... In the location C:\Myfolder i could have, lets say: temp_170807.txt temp_180807.txt, etc.... But only one file at a time will be present so i need to give a generic criteria like: C:\\My folder\\temp_*.txt Hope you got the problem

                S Offline
                S Offline
                SnaKeBeD
                wrote on last edited by
                #9

                better u don use the multiple selection like this, use a CFileDialog class for that purpose, refer MSDN

                swaroop

                S 1 Reply Last reply
                0
                • S SnaKeBeD

                  better u don use the multiple selection like this, use a CFileDialog class for that purpose, refer MSDN

                  swaroop

                  S Offline
                  S Offline
                  SnaKeBeD
                  wrote on last edited by
                  #10

                  actullay by giving * wont solve ur problem, os else wat u can do is , if the file name ends with constant increase like temp_001, temp_002, etc just put the file open in a loop , concat the file name with the count (eg001,002) and open it and use it, don forget to close before u leave the loop:)

                  swaroop

                  1 Reply Last reply
                  0
                  • _ __yash__

                    i m opening only one file at a time.... only one file at any given time will be present in the folder: C:\\My folder\\ i.e. i have either text_1000.txt or text_1001.txt in that location so i need to give something like text_*.txt i hope its clear...

                    S Offline
                    S Offline
                    sw thi
                    wrote on last edited by
                    #11

                    I guess you will have to find the file name at runtime and then read it?!! There is a class called CFileFind MFC, you can use that, CFileFind finder; finder.FindFile("C:\\Design Docs\\temp*.txt"); // this will find your file finder.FindNextFile(); // it is compulsory to call this function before you call GetFilePath CString filename = finder.GetFilePath(); // this will get the file name along with the path, so you can use this to open the file and read. finder.Close(); Hope this solves your problem. Happy weekend.

                    "What's on your mind, if you will allow the overstatement?"

                    _ 1 Reply Last reply
                    0
                    • S sw thi

                      I guess you will have to find the file name at runtime and then read it?!! There is a class called CFileFind MFC, you can use that, CFileFind finder; finder.FindFile("C:\\Design Docs\\temp*.txt"); // this will find your file finder.FindNextFile(); // it is compulsory to call this function before you call GetFilePath CString filename = finder.GetFilePath(); // this will get the file name along with the path, so you can use this to open the file and read. finder.Close(); Hope this solves your problem. Happy weekend.

                      "What's on your mind, if you will allow the overstatement?"

                      _ Offline
                      _ Offline
                      __yash__
                      wrote on last edited by
                      #12

                      Thank you very much Swathee It solved my problem Happy weekend :)

                      1 Reply Last reply
                      0
                      • _ __yash__

                        CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead); In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC application

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

                        I suggest studying up on the concept of absolute vs. relative paths.


                        "A good athlete is the result of a good and worthy opponent." - David Crow

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        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