?
Solved

FILE FUNCTIONS: is there a function to copy a whole folder?

Posted on 2003-02-21
3
Medium Priority
?
204 Views
Last Modified: 2006-11-17
Hi,

I was just wondering if there is a function to copy a whole folder...I know there is CopyFile.

BOOL CopyFile(
  LPCTSTR lpExistingFileName,
                          // pointer to name of an existing file
  LPCTSTR lpNewFileName,  // pointer to filename to copy to
  BOOL bFailIfExists      // flag for operation if file exists
);
 
But I can't find anything to copy a whole folder...

Thanks in Advance..

Lou
0
Comment
Question by:loudogz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:Salte
ID: 7993058
Yes there is, not sure if you like the answer though. Since I see from your post that you're in a windoze machine I'll give you the answer for windows:

system("xcopy /s...other options...args..");

You can also use CreateProcessEx() or something like that instead of system() but the net result is more or less the same.

Under unix the system("cp -r source... dest"); should work.

This was perhaps not the answer you were looking for but it does the job.

You can also use FindFirstFile()/FindNextFile() and copy the directory that way. Check the flag ISDIR for directory, if directory you copy it by recursively calling yourself to copy it. If it is a plain regular file you call CopyFile() to copy the file.

Alf
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7993194
Use 'SHFileOperation()', it is designed for that purpose:

    SHFILEOPSTRUCT  sfo;
    ZeroMemory  (   &sfo,   sizeof  (   SHFILEOPSTRUCT));

    sfo.wFunc   =   FO_COPY;
    sfo.pFrom   =   "c:\\path\\*.*";
    sfo.pTo     =   "c:\\anotherpath";
    sfo.fFlags  =   FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI;

    if  (   SHFileOperation (   &sfo))
        {
            // error
        }
0
 

Author Comment

by:loudogz
ID: 7995573
Thanks, You da "Man"
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question