The essence of the problem:
When copying a file to a directory where a file with the same name already exists with the ReadOnly attribute, the CopyFile copy function returns FALSE. One solution is to remove the RO attribute from the target file and retry the copy, which significantly slows down the process when copying large volumes of small files (100k +). Are there any methods that allow copying a ro-file into another ro-file into 1 action?
Code:
CString sFrom = _T("D:\test1\test.log"); CString sTo = _T("D:\test2\test.log"); // Этот файл должен быть read-only BOOL bRet = CopyFile(sFrom, sTo, FALSE); if ( FALSE == bRet ) { DWORD dwAttr = GetFileAttributes(sTo); dwAttr &= ~FILE_ATTRIBUTE_READONLY; SetFileAttributes(sTo, dwAttr); bRet = CopyFile(sFrom, sTo, FALSE); } return bRet;
GetLastError()check on error - PinkTuxsystem("xcopy /r /y src dst");- αλεχολυτ