Click to See Complete Forum and Search --> : copying complete directory


felakuti
June 16th, 2002, 04:33 PM
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.

sandodo
June 17th, 2002, 04:20 AM
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

sandodo
June 17th, 2002, 04:48 AM
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. :p

Plastelin
June 17th, 2002, 05:01 AM
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