CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Folder copying

  1. #1
    Join Date
    May 1999
    Posts
    2

    Folder copying

    Hello everybody,

    can somebody give me any hints on how to perform copy operations off complete folders (and subfolders) to another location by using VC++ commands?
    (I am using VC++ 4.2)

    Thanks,
    Johan


  2. #2
    Join Date
    May 1999
    Location
    Paris, France
    Posts
    216

    Re: Folder copying

    Use FindFirstFile to list all the files of the directory
    then do a loop with FindNextFile and CopyFile

    You'll need also CreateDirectory


  3. #3
    Join Date
    May 1999
    Location
    L.A.
    Posts
    20

    Re: Folder copying


    Below is a program which is a modification of a method I have used recently.
    It works under Visual C++ 6.0 and Windows NT 4.0, but I believe it works
    in other machine configurations too.

    Note that there is no error or exception handling (and I'm a lousy programmer). :-)

    /Johan


    // "foldername" is your source folder, dest_name is the root to the destination.
    // This algorithm searches "depth-first", which perhaps is not the most efficient

    void YourClass::copy_folder(CString *foldername, CString *dest_name)
    {
    struct _finddata_t buffer;
    CString b_name;
    long handle;

    if (_chdir(*foldername) != -1L) {
    handle = _findfirst("*", &buffer);
    if (handle != -1L)
    do { // do this if atlest one file is present
    b_name = buffer.name;
    if (b_name != "." && b_name != "..") {
    if ((buffer.attrib & _A_SUBDIR) != _A_SUBDIR)
    // Copy the file here to dest_name
    else {
    // It was a subdirectory, create a new subdirectory here at dest_name
    // Do a recursive call below to extract the subfolder
    copy_folder(&(*foldername + "/" + b_name), &(*dest_name + "/" + b_name));
    }
    }
    }
    while (_findnext(handle, &buffer) == 0);
    }
    }





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured