Thread: copy directory in C

  1. #1
    Dbyte
    Guest

    Question copy directory in C

    Hi all,
    Does anyone have any C programming sample code or links to some that would show me how to copy a directory (& all its files) from 1 location to another on a Windows machine? I don't need to open or manipulate the directory in any way, just to copy it to a new location using an absolute path. I am a complete newbie to C programming, so any help would be appreciated.

  2. #2
    Dbyte
    Guest
    Okay, so I've gotten the copy part to work with the following code:

    {
    system("copy C:\\MYDOCU~1 C:\\test");
    }

    But there is a problem. The folder MYDOCU~1 has sub-folders within it that are not being copied over. How do I modify or alter the code above to ensure that the folders are copied over to the new location as well as the files?

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    system("xcopy C:\\MYDOCU~1 C:\\test /e/v/s");

  4. #4
    Dbyte
    Guest

    Thumbs up

    Scarlet7,
    Thanks so much! I made a few changes to your modifiers for xcopy, but otherwise it works perfect.

    -Dbyte

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 10:56 AM
  2. copy files to samba
    By lollobrigido in forum Linux Programming
    Replies: 3
    Last Post: 04-28-2008, 06:31 AM
  3. How to create copy of Directory?
    By shwetha_siddu in forum C Programming
    Replies: 4
    Last Post: 04-23-2008, 06:31 AM
  4. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  5. Finding files in a directory
    By smarta_982002 in forum C Programming
    Replies: 1
    Last Post: 01-25-2008, 10:10 AM