CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2002
    Posts
    2

    Question copying complete directory

    I´m not an expert, so sorry for this question: how do I easily copy a whole directory with it´s folders and files to another place without using MFC. I´m on wxWindows and it has to work on MS and Mac.
    Thanks a lot for your answers.

  2. #2
    Join Date
    Jun 2002
    Posts
    137
    you can use the

    you can use the
    _findfirst()
    _findnext()
    _findclose()
    to search the files and sub-folders like the following;

    struct _finddata_t fd;

    long handle = _findfirst("C:\\*", &fd);

    _findnext(handle, &fd);

    _findclose(handle);

    for files, the fd.attrib euqals to 32, for folder, fd.attrib equals to 16

    and for copy file to another directory, you can use fstream like the following:
    ifstream inputFile("c:\\temp.txt",ios::binary);

    ofstream outputFile("c:\\temp2.txt",ios::binary);

    outputFile << inputFile.rdbuf();


    for detailed usage, you can go to MSDN library

  3. #3
    Join Date
    Jun 2002
    Posts
    137

    Lightbulb

    Anybody can give the pure c code or c++ code for the search and copy?

    for the
    _findfirst()
    _findnext()
    _findclose()
    there are replacement in windows.h(donot know whether they are MFC functions or not), which are
    FindFirstFile()
    FindNextFile()
    FindClose()

    and for read and write, there are
    _open(), _read(), _write(), fread() also from io.h


    is there ant link for the information on what are those so-called pure c++, pure c functions. many people ask for only C/C++ code.

  4. #4

    Angry

    Never use sintax like this, or it provide many bugs:
    1) whay should we read and write file in memory, throw all the filtres, we can coll CopyFile() or MoveFile(), it optimized by the OS.
    2) aspecialy for 'fstreams' they are incorrectly working with '\n', '\r' symbols, so in case of this syntax you will get new file with doubbled '\n' ...

    ifstream inputFile("c:\\temp.txt",ios::binary);

    ofstream outputFile("c:\\temp2.txt",ios::binary);

    outputFile << inputFile.rdbuf();


    for detailed usage, you can go to MSDN library

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured