Solved

copying files from one directory to another one on a network

Posted on 2003-11-27
4
462 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
[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
  • 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

696 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