none
How to Copy a File to Appdata Folder RRS feed

  • Question

  • How to Copy a File to Appdata Folder?

    I can enter the Appdata-Folder with SHGetFolderPath and CSIDL_APPDATA. But how do I copy a File e.g. C:\Test.txt to Appdata?

     

    Sry I have started a Discussion :)

    • Changed type nick_C-- Wednesday, February 23, 2011 1:54 PM
    Wednesday, February 23, 2011 1:53 PM

Answers

  • On 2/25/2011 4:45 PM, nick_C-- wrote:

    The Error-Message vanishes :D But here is my Code again: He doesn't want to copy the File :(

    Does the Adobe subfolder exist? CopyFile won't create it if it doesn't.

    Does SHGetSpecialFolderPath include the trailing backslash in the path? My example assumes it does, but if not, just add it yourself:

    string src = app_path + "\\test.txt";

    For debugging purposes, print src and dst, check that they look right.

    If CopyFile still fails, check the value of GetLastError() after that.


    Igor Tandetnik

    Friday, February 25, 2011 10:06 PM

All replies

  • nick_C-- wrote:

    How to Copy a File to Appdata Folder?

    The same way you copy a file to any other folder. E.g. with  CopyFile[Ex], or SHFileOperation.


    Igor Tandetnik

    Wednesday, February 23, 2011 2:10 PM
  • Yes, but the AppData-Folder is variable! So I donÄt know how to specify the Appdata Folder in CopyFile() Function!
    Wednesday, February 23, 2011 2:20 PM
  • nick_C-- wrote:

    Yes, but the AppData-Folder is variable! So I don�?t know how to  specify the Appdata Folder in CopyFile() Function!

    Naturally, you call SHGetFolderPath first, and then pass the result to  CopyFile.


    Igor Tandetnik

    Wednesday, February 23, 2011 2:49 PM
  • And how do I pass the Result?
    Wednesday, February 23, 2011 2:57 PM
  • nick_C-- wrote:

    And how do I pass the Result?

    You don't know how to pass a parameter to a function? How do you manage  to call SHGetFolderPath, then?


    Igor Tandetnik

    Wednesday, February 23, 2011 3:03 PM
  • RIght now, I have set the Variable "App" To the AppData Folder. But how can I call the CopyFile() Function with the App-Variable? My Code:

     

    #include <iostream>
    #include "shlobj.h"
    
    using std::cout;
    using std::endl;
    using std::cin;
    
    int main()
    {
      char App[MAX_PATH];
      SHGetSpecialFolderPath(NULL, App, CSIDL_APPDATA, FALSE);
      cout <<"AppData Ordner:"<< App << endl;
      cout <<"Um zu Kopieren, ENTER drücken"<<endl;
      cin.get();
      CopyFile("App/test.txt","App/Adobe/Test1.txt", false);
      return 0;
    }
    

    Friday, February 25, 2011 8:24 PM
  • On 2/25/2011 3:24 PM, nick_C-- wrote:

    RIght now, I have set the Variable "App" To the AppData Folder. But how can I call the CopyFile() Function with the App-Variable? My Code:

    [code]
       char App[MAX_PATH];
       SHGetSpecialFolderPath(NULL, App, CSIDL_APPDATA, FALSE);
       CopyFile("App/test.txt","App/Adobe/Test1.txt", false);

    Something along these lines:

    string app_path = App;
    string src = app_path + "test.txt";
    string dst = app_path + "Adobe/Test1.txt";
    CopyFile(src.c_str(), dst.c_str(), false);


    Igor Tandetnik

    Friday, February 25, 2011 8:38 PM
  • Looks good, thanks :)

    But now he says LNK1169 and when I type /FORCE, he doesn't copy the files!

    Friday, February 25, 2011 9:25 PM
  • On 2/25/2011 4:25 PM, nick_C-- wrote:

    Looks good, thanks :)

    But now he says LNK1169 and when I type /FORCE, he doesn't copy the files!

    What is the exact text of error messages?


    Igor Tandetnik

    Friday, February 25, 2011 9:36 PM
  • The Error-Message vanishes :D But here is my Code again: He doesn't want to copy the File :(

     

    #include <iostream>
    #include "shlobj.h"
    #include <string>
    #include "winbase.h"
    
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;
    
    int main()
    {
     char App[MAX_PATH];
     SHGetSpecialFolderPath(NULL, App, CSIDL_APPDATA, FALSE);
     cout <<"AppData Ordner:"<< App << endl;
     cout <<"Um zu Kopieren, ENTER drücken"<<endl;
     cin.get();
     string app_path = App;
     string src = app_path + "test.txt";
     string dst = app_path + "Adobe/test.txt";
     CopyFile(src.c_str(),dst.c_str(), false);
     return 0;
    }
    

     

    Friday, February 25, 2011 9:45 PM
  • On 2/25/2011 4:45 PM, nick_C-- wrote:

    The Error-Message vanishes :D But here is my Code again: He doesn't want to copy the File :(

    Does the Adobe subfolder exist? CopyFile won't create it if it doesn't.

    Does SHGetSpecialFolderPath include the trailing backslash in the path? My example assumes it does, but if not, just add it yourself:

    string src = app_path + "\\test.txt";

    For debugging purposes, print src and dst, check that they look right.

    If CopyFile still fails, check the value of GetLastError() after that.


    Igor Tandetnik

    Friday, February 25, 2011 10:06 PM
  • YEEEEES it works! I added the \\ before test.txt and Adobe!

     

    Thanks

    Friday, February 25, 2011 10:10 PM
  • If you cant just answer the question and show someone how to do it, then dont respond at all.

    Wednesday, November 6, 2019 4:17 PM