#include <windows.h>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;

const char * src_file = "QFN64 230551-CU-A";
const char * dst_file = "Test";

int main()
{
	int file_size = 0;
	string m_Path = src_file;

	WIN32_FIND_DATAA file_data;//取得File檔案資訊
	HANDLE handle;
	handle = ::FindFirstFileA(m_Path.c_str(), &file_data);
	if( handle != INVALID_HANDLE_VALUE )
	{
		::FindClose(handle);
		if ( !(file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
		{
			file_size = file_data.nFileSizeLow;////取得File檔案大小
		}
		puts("Success!!");
	} else {
		puts("Error!!");
	}

	FILE *fp = fopen(src_file, "rb");
	char *buf = (char*)malloc(file_size+10);

	if(buf==NULL){
		puts("allocate fail.");
		getchar();
		return 1;
	}

	size_t ret = fread(buf, 1, file_size, fp);
	printf("file_size = %u, ret = %u\n", file_size, ret);
	buf[file_size] = 0;

	FILE *fw = fopen(dst_file, "wb");
	fwrite(buf, sizeof(buf[0]), file_size, fw);
	fclose(fw);

	free(buf);
	getchar();
	return 0;
}