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. How to change the path were files are created

How to change the path were files are created

Scheduled Pinned Locked Moved C / C++ / MFC
questionvisual-studiohelptutorial
17 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.
  • D dliviu

    i have this code:

    FILE* file;

    file=_wfopen(L"fisier.txt",L"w,ccs=UNICODE");
    fwrite(text.c_str(),sizeof(wchar_t),wcslen(text.c_str()),file);
    fclose(file);

    the problem I'm having is that the file "fisier.txt" is saved on desktop and not where my app is. How can I change the location from VS 2005 so that the file is created in my app's directory? I don't want to change the path in the code.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Use the Common Item Dialog[^] to allow the user to specify the path to the file. Or use one of the Shell functions[^] that provide the user's application data path.

    Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

    D 1 Reply Last reply
    0
    • L Lost User

      Use the Common Item Dialog[^] to allow the user to specify the path to the file. Or use one of the Shell functions[^] that provide the user's application data path.

      Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

      D Offline
      D Offline
      dliviu
      wrote on last edited by
      #3

      I'm thinking is some setting is Visual Studio but I cannot find it. And how come it saves the file on desktop? I cannot see any logic in that.

      L 1 Reply Last reply
      0
      • D dliviu

        I'm thinking is some setting is Visual Studio but I cannot find it. And how come it saves the file on desktop? I cannot see any logic in that.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        dliviu wrote:

        I'm thinking is some setting is Visual Studio

        Why are you thinking that?

        dliviu wrote:

        And how come it saves the file on desktop?

        The desktop is just a folder like everywhere else.

        dliviu wrote:

        I cannot see any logic in that.

        The logic is missing from your code. If you do not tell Windows where to store your files then it is going to have to make a decision based on 'best guess'.

        Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

        D V 2 Replies Last reply
        0
        • L Lost User

          dliviu wrote:

          I'm thinking is some setting is Visual Studio

          Why are you thinking that?

          dliviu wrote:

          And how come it saves the file on desktop?

          The desktop is just a folder like everywhere else.

          dliviu wrote:

          I cannot see any logic in that.

          The logic is missing from your code. If you do not tell Windows where to store your files then it is going to have to make a decision based on 'best guess'.

          Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

          D Offline
          D Offline
          dliviu
          wrote on last edited by
          #5

          There must be a setting because i downloaded a vs c++ project which saves the files created with fopen in the app's directory and not on desktop!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

          L 1 Reply Last reply
          0
          • D dliviu

            There must be a setting because i downloaded a vs c++ project which saves the files created with fopen in the app's directory and not on desktop!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            It's nothing to do with Visual Studio, it depends on the environment of the executable program (which does not necessarily run inside Visual Studio). And a single exclamation mark is enough to make your point!

            Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

            D 1 Reply Last reply
            0
            • L Lost User

              It's nothing to do with Visual Studio, it depends on the environment of the executable program (which does not necessarily run inside Visual Studio). And a single exclamation mark is enough to make your point!

              Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

              D Offline
              D Offline
              dliviu
              wrote on last edited by
              #7

              and how can I tell windows where to store my c++ created files??

              L D 2 Replies Last reply
              0
              • D dliviu

                and how can I tell windows where to store my c++ created files??

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                Do as I suggested and use one of the options I already told you about, and provided links to.

                Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

                1 Reply Last reply
                0
                • D dliviu

                  i have this code:

                  FILE* file;

                  file=_wfopen(L"fisier.txt",L"w,ccs=UNICODE");
                  fwrite(text.c_str(),sizeof(wchar_t),wcslen(text.c_str()),file);
                  fclose(file);

                  the problem I'm having is that the file "fisier.txt" is saved on desktop and not where my app is. How can I change the location from VS 2005 so that the file is created in my app's directory? I don't want to change the path in the code.

                  _ Offline
                  _ Offline
                  _AnsHUMAN_
                  wrote on last edited by
                  #9

                  You can always get the path from where the exe is running using GetModuleFileName and extract the required path and append it in the wfopen function for the file name .Then your file should be created in the app directory itself. Though this is a strange behaviour that you are getting, this is just another way for achieving what you want.

                  You talk about Being HUMAN. I have it in my name AnsHUMAN

                  D 1 Reply Last reply
                  0
                  • L Lost User

                    dliviu wrote:

                    I'm thinking is some setting is Visual Studio

                    Why are you thinking that?

                    dliviu wrote:

                    And how come it saves the file on desktop?

                    The desktop is just a folder like everywhere else.

                    dliviu wrote:

                    I cannot see any logic in that.

                    The logic is missing from your code. If you do not tell Windows where to store your files then it is going to have to make a decision based on 'best guess'.

                    Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

                    V Offline
                    V Offline
                    Vaclav_
                    wrote on last edited by
                    #10

                    "The desktop is just a folder like everywhere else." Would it be more correct if we say that the "desktop" is the parent / main (Windows) application and that is why the file goes there if no path is specified? Just curious. Also it seems "illogical" / awkward to open a file ( on desktop ) and than save it elsewhere. But - whatever floats your boat. Vaclav

                    L 1 Reply Last reply
                    0
                    • V Vaclav_

                      "The desktop is just a folder like everywhere else." Would it be more correct if we say that the "desktop" is the parent / main (Windows) application and that is why the file goes there if no path is specified? Just curious. Also it seems "illogical" / awkward to open a file ( on desktop ) and than save it elsewhere. But - whatever floats your boat. Vaclav

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      Vaclav_Sal wrote:

                      Would it be more correct

                      I was trying not to complicate things, saying "it's just a folder" was the simplest explanation I could come up with.

                      Vaclav_Sal wrote:

                      Also it seems "illogical" /   awkward to open a file ( on desktop ) and than save it elsewhere.

                      Sorry, I don't understand what you are saying here.

                      Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

                      1 Reply Last reply
                      0
                      • _ _AnsHUMAN_

                        You can always get the path from where the exe is running using GetModuleFileName and extract the required path and append it in the wfopen function for the file name .Then your file should be created in the app directory itself. Though this is a strange behaviour that you are getting, this is just another way for achieving what you want.

                        You talk about Being HUMAN. I have it in my name AnsHUMAN

                        D Offline
                        D Offline
                        dliviu
                        wrote on last edited by
                        #12

                        Thank you for your answer. This is indeed a strange behaviour. I will use GetModuleFileName. It seems that I have no other option.

                        L 1 Reply Last reply
                        0
                        • D dliviu

                          Thank you for your answer. This is indeed a strange behaviour. I will use GetModuleFileName. It seems that I have no other option.

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #13

                          dliviu wrote:

                          This is indeed a strange behaviour.

                          No, this is quite normal.

                          dliviu wrote:

                          It seems that I have no other option.

                          You have quite a few options, two more of which I suggested above.

                          Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

                          1 Reply Last reply
                          0
                          • D dliviu

                            i have this code:

                            FILE* file;

                            file=_wfopen(L"fisier.txt",L"w,ccs=UNICODE");
                            fwrite(text.c_str(),sizeof(wchar_t),wcslen(text.c_str()),file);
                            fclose(file);

                            the problem I'm having is that the file "fisier.txt" is saved on desktop and not where my app is. How can I change the location from VS 2005 so that the file is created in my app's directory? I don't want to change the path in the code.

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #14

                            There is a 'working directory' setting which I believe is on the debug menu, or some such. It is where you can specify the exe to be debuged and any arguments too. This might change the behaviour, but I am guessing at some point you will want the app to run outside the debugger, so you are going to have to write code to set the path where the file is saved.

                            ============================== Nothing to say.

                            D 1 Reply Last reply
                            0
                            • L Lost User

                              There is a 'working directory' setting which I believe is on the debug menu, or some such. It is where you can specify the exe to be debuged and any arguments too. This might change the behaviour, but I am guessing at some point you will want the app to run outside the debugger, so you are going to have to write code to set the path where the file is saved.

                              ============================== Nothing to say.

                              D Offline
                              D Offline
                              dliviu
                              wrote on last edited by
                              #15

                              I know about the working directory option. I've set it but to no avail. I'm gonna use GetModuleFileName. Thanks!

                              1 Reply Last reply
                              0
                              • D dliviu

                                and how can I tell windows where to store my c++ created files??

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

                                This question is non-sensical. Why would Windows care where they are stored?

                                "One man's wage rise is another man's price increase." - Harold Wilson

                                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                                1 Reply Last reply
                                0
                                • D dliviu

                                  i have this code:

                                  FILE* file;

                                  file=_wfopen(L"fisier.txt",L"w,ccs=UNICODE");
                                  fwrite(text.c_str(),sizeof(wchar_t),wcslen(text.c_str()),file);
                                  fclose(file);

                                  the problem I'm having is that the file "fisier.txt" is saved on desktop and not where my app is. How can I change the location from VS 2005 so that the file is created in my app's directory? I don't want to change the path in the code.

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

                                  dliviu wrote:

                                  the problem I'm having is that the file "fisier.txt" is saved on desktop and not where my app is.

                                  It's the difference between a relative path vs. an absolute path.

                                  "One man's wage rise is another man's price increase." - Harold Wilson

                                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                  "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                                  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