How to copy or move file with progress?
![]()
In old Win98 days, File copying progress notification was horrific. Even if you have a lot of data to copy, it always says – you have 5 more minutes to finish.
Well, how to copy or move file with accurate progress?

![]()
You can use the api – CopyFileEx() for copying data with progress and MoveFileEx() to move files with progress. Both are more or less similar in usage. In both cases, just call the apis by providing the callback function pointer. System will give callback notification for the progress. See the code snippet of CopyFileEx().
// Callback function for handling progress notification.
DWORD CALLBACK CopyProgressRoutine(
LARGE_INTEGER TotalFileSize,
LARGE_INTEGER TotalBytesTransferred,
LARGE_INTEGER StreamSize,
LARGE_INTEGER StreamBytesTransferred,
DWORD dwStreamNumber,
DWORD dwCallbackReason,
HANDLE hSourceFile,
HANDLE hDestinationFile,
LPVOID lpData )
{
// Calculate the percentage here.
double Percentage = ( double(TotalBytesTransferred.QuadPart) /
double(TotalFileSize.QuadPart) ) * 100;
// Continue the file copy. It can also be stopped.
return PROGRESS_CONTINUE;
}
void CDlgDlg::OnCopy()
{
// Copy the file.
CopyFileEx( _T("c:\\Jijo\\Games.rar"),
_T("c:\\Jijo\\GamesBackup.rar"),
CopyProgressRoutine,
0,
FALSE,
0 );
}
![]()
CopyFIleEx() and MoveFileEx() are available only from Windows NT onwards. So don’t forget to add _WIN32_WINNT=0×0400 to project settings.
![]()
Targeted Audience – Beginners.
Hi, this seems like it should work, but I am having problems.
If I don’t call the copyprogress routine, the files copies fine. If I call the progress routine, the file doesn’t copy?
using your example, all I did was change the src and dest to be test.txt files, I had to add a type cast (LPPROGRESS_ROUTINE) when calling the copyprogress routine from copyfileEX, and in the copyprogresroutine, I had to add static before DWORD.
Have you seen this behaviour before? Is it something I’m doing wrong in VS?