?
Solved

copying files from one directory to another one on a network

Posted on 2003-11-27
4
Medium Priority
?
463 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

764 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