Thread: Copying an entire directory

  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212

    Copying an entire directory

    Maybe I didn't look hard enough but I couldn't find this from the search feature. I'm looking for a way to copy an entire directory ( i'll put the word folder here, so it'll be easier to search for ) using winAPI. Preferably it won't involve the horrible findfirst and findnext functions, I hate them.

    ...and how would I go about deleting an entire directory...?

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    I believe FindFirstFile and FindNextFile are your best way. They will tell you your subdirectories too so that you can copy those over as well. Sorry that you hate them so much

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    If you are using mingw or cygwin (i don't think this one will work on msvc++) try the attached code. Well try it even if you are using msvc, for the most part it should be ansi c.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    thank's i'll have a look at that

  5. #5
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Hehe woah.

    there's a problem with line 53:
    Code:
        strcpy(buffer, argv[0]);
    this erases the directory in which the program is running. I think it should be

    Code:
        strcpy(buffer, argv[1]);
    I guess it's lucky I backed up everything onto CD [for the first time in forever] yesterday, because I just lost my projects directory.

    lol

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Heheh oops. I just remembered I sent you windel.c not wincpy.c. One was a program that I made for deleting windows directory (where I usually put the program) before re-installing windows. I must have deleted the other one, which was the one I meant to give you. Sorry about the mix up. The good news is that it only crawls upward through directories and won't delete parent directories.

  7. #7
    Unregistered
    Guest
    Use SHFileOperation. It will copy entire directory trees using the windows shell.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. copying file from one user directory to another
    By Bargi in forum Linux Programming
    Replies: 6
    Last Post: 05-17-2009, 04:09 PM
  2. Copying an entire directory
    By JustMax in forum C Programming
    Replies: 3
    Last Post: 03-11-2009, 04:06 PM
  3. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  4. Copying a whole directory and its content
    By Enira in forum C Programming
    Replies: 4
    Last Post: 03-12-2006, 02:13 PM
  5. Copying a Directory to the Clipboard
    By Buiden in forum C++ Programming
    Replies: 0
    Last Post: 07-15-2005, 12:21 PM