verify after copying

Hi All
I have a query related to verification performed while coping.
So anybody can tell me how this verification is performed bit by bit or any link
related to the source code.

Thanks
Ajit Mote
The verify request is passed to the device driver, it's not performed by the app or API.
Hi

I have code to copy from one drive to the another but after copy operation I need to verify the copy operation. Then how can I verify the copy operation bit by bit so that I can say copy is performed without ERROR.

How to pass the verify request to the device driver ?

Thanks.
Open both files in read-only mode and compare them block by block. Something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <string>
#include <fstream>
#include <sys/stat.h>

bool compare(const std::string &srcfilename, const std::string &dstfilename)
{
	// check size
	struct stat srcbuf, dstbuf;
	stat(srcfilename.c_str(), &srcbuf);
	stat(dstfilename.c_str(), &dstbuf);
	if (srcbuf.st_size != dstbuf.st_size)
		return false;

	// check content
	std::ifstream src(srcfilename.c_str(), std::ios::binary);
	std::ifstream dst(dstfilename.c_str(), std::ios::binary);
	while (src && dst)
	{
		char srcbuf[4096], dstbuf[4096];
		std::streamsize srcpos = src.gcount();

		src.read(srcbuf, sizeof(srcbuf));
		dst.read(srcbuf, sizeof(srcbuf));
		if (src.gcount() != dst.gcount() ||
		    memcmp(srcbuf, dstbuf, src.gcount() - srcpos) != 0)
		{
			return false;
		}
	}

	return !(src || dst);
}
Last edited on
Thanks for your reply

This code is working properly with the files with small size. But it is not working with .rar or .zip files with large size. If I increase the buffer size of source and destination it runs proper in some situation. I need to compare the files with large size.

Thanks.

Hi

For comparing files with above code takes large amount of time. Then how the verify operation is performed in various copying tool more faster. Is any efficient code is available so that I do verify copy operation fast.

Thanks
Ajit Mote.
Yes, there are faster versions, but if you can't understand this I won't go into it. Maybe someone else will.

BTW, what's wrong with CopyFile()?
Coping file from one source to destination is over. Now I have to verify that files are copied without an error so that I am comparing those files bit by bit so as to confirm that files are copied without an error. I need a help that how the compare operation will work efficiently.
Thanks to all for your reply.
Topic archived. No new replies allowed.