Thread: Copy a file?

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13

    Copy a file?


    Hi i was wondering if anyone knew how I can copy a file (with C++) and then place it in a folder and overwrite a file in that folder with the same name.

    Thanks

    Edit: Oh yea, and i was wondering how i could open a file that has a space in the folder name like.. C:\Documents and Settings\default\My Documents how can i write that in C++ Coz it doesnt let me do spaces :(
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    See the CopyFile() and CopyFileEx() documentation in MSDN

    There should be no problems in using spaces in filenames with these functions.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    oh sweet thanks
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    Hi, Sorry if i should newb but in order to copy a file, i have this code..

    Code:
    BOOL CopyFile(
      LPCTSTR lpExistingFileName,
      LPCTSTR lpNewFileName,
      BOOL bFailIfExists
    );
    but... do i just leave lpExistingFileName as that? or do i change it with like C:\Whatever\I\Want\To\Copy

    Thanks in advance.

    -Kyle
  8. #5
  9. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0
    My experience, which is limited, is that you need to use double backslashes because of real expressions.
    Example: C:\\Whatever\\I\\Want\\To\\Copy



    Eric
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    Yea i know but what i mean is like how do i tell the program the path to the file? do i go like

    #define lpExistingFileName C:\\*******

    or what ?

    Thanks.
  12. #7
  13. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0
    Here is a good example...

    MSDN

    Eric
  14. #8
  15. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    You can just use something like this:
    Code:
    CopyFile("C:\\path\\to\\source\\file", "C:\\path\\to\\destination\\file", FALSE);
    If you don't understand what this LPCTSTR business is all about, I suggest you research Hungarian Notation on the web, or look it up in a Visual C++ programming book. Practically all of Micro$oft's code uses Hungarian Notation as their standard naming convention and it's good to become slightly familiar with it.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    Ok, Thanks a lot :D

IMN logo majestic logo threadwatch logo seochat tools logo