Is there a way in win32 C++ that I can copy all the files inside a CD Rom and save them in a folder located somewhere else (where the folder location will be specified)? Is there a win32 C++ function to do this? The docs show the function SHFileOperationA() but can this copy all the files in a CD Rom?
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!\n");
else
wprintf(L"CopyFile fails with error: %d\n", GetLastError());
} while (FindNextFile(searchHdl, &fData));
}
FindClose(searchHdl);