CopyFile() wants you to specify the name of the file being copied
though. What if you don't know the name of the files
You can use FindFirstFile
and FindNextFile
combine with CopyFile
.
Assume your CD ROM drive is E:
, you can try the following example to see if it helps.
WIN32_FIND_DATA fData;
HANDLE searchHdl = FindFirstFile(L"E:\*", &fData);
if (INVALID_HANDLE_VALUE != searchHdl)
{
do {
std::wstring existingFileName(L"E:\");
existingFileName.append(fData.cFileName);
std::wstring newFileName(L"D:\");
newFileName.append(fData.cFileName);
if (CopyFile(existingFileName.c_str(), newFileName.c_str(), TRUE))
wprintf(L"CopyFile success!
");
else
wprintf(L"CopyFile fails with error: %d
", GetLastError());
} while (FindNextFile(searchHdl, &fData));
}
FindClose(searchHdl);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…