Solved

copying files from one directory to another one on a network

Posted on 2003-11-27
4
460 Views
Last Modified: 2010-04-01
i have looked around on internet forums for the best way to copy files from one dirctory to another. can anyone start me off or point me in the right direction
0
Comment
Question by:koreviper
  • 2
4 Comments
 
LVL 2

Expert Comment

by:waseemanis
ID: 9830839
The best way to do this would be to

get into a directory, findfiles and copy them to the destination ONE by ONE. You would want to ignore the "." and ".." files while doing this.

0
 

Author Comment

by:koreviper
ID: 9831324
see there is about 50 files and also sub folders in this directory. if i was going to do them one by one. it would take to long:S. The directory is for a program "Retail manager" and i want to back up the whole program just incase something happens to the system with the data.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 50 total points
ID: 9832744
On Windows you may use code like below:


#include <string.h>
#include <iostream.h>
#include <windows.h>


#define MAX_LEN_CMDLINE                 512
                                       
#define DEF_PROC_ATTR_SEC_DESC_NULL     NULL
#define DEF_THRD_ATTR_SEC_DESC_NULL     NULL
#define DEF_ENV_BLOCK_NULL                       NULL
#define DEF_CUR_DIR_NULL                           NULL
#define INHERIT_HANDLES_FALSE                  FALSE

int main(int nArgs, char* szArgs[])
{
    char szCmdLine[MAX_LEN_CMDLINE] = "xcopy d:\\folder d:\\folder.bck\\ /S /E";

    for (int n = 1; n < nArgs; n++)
    {
        strcat(szCmdLine, szArgs[n]);
        strcat(szCmdLine, " ");
    }

    STARTUPINFO         si;
    memset(&si, 0, sizeof(STARTUPINFO));

    si.cb           = sizeof(STARTUPINFO);
    si.dwFlags      = STARTF_USESHOWWINDOW;
    si.wShowWindow  = SW_SHOWMINIMIZED;

    cout << szCmdLine << "\n";

    PROCESS_INFORMATION pi;
    memset(&si, 0, sizeof(PROCESS_INFORMATION));

    if (!CreateProcess(NULL,
                       szCmdLine,
                       DEF_PROC_ATTR_SEC_DESC_NULL,
                       DEF_THRD_ATTR_SEC_DESC_NULL,
                       INHERIT_HANDLES_FALSE,
                       // DETACHED_PROCESS,
                       CREATE_NEW_CONSOLE,
                       DEF_ENV_BLOCK_NULL,
                       DEF_CUR_DIR_NULL,
                       &si,
                       &pi)
       )
    {
        cout << GetLastError() << "\n";
        return GetLastError();
    }
    cout << "CreateProcess ok pi.hProcess=" << pi.hProcess << "\n";

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );

   

      return 0;
}

-----------------------------------------------------------------------

On all  OS you may use  system()



/* SYSTEM.C: This program uses
 * system to xcopy a folder and all its subfolders
 */
#include <process.h>
void main( void )
{
   system( "xcopy d:\\folder d:\\folder.bck\\ /S /E" );
}

----------------------------------------------------------------------

However, in my opinion the copy isn't faster as if you would recursively
make a findfile on all directories and copy all files one-by-one.

Regards, Alex





0
 

Author Comment

by:koreviper
ID: 9833721
thanks, it's working exactly the way i wanted it to.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

713 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