Solved

copying files from one directory to another one on a network

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

10 Experts available now in Live!

Get 1:1 Help Now