Solved

copying files from one directory to another one on a network

Posted on 2003-11-27
4
457 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now