使用win32 c++复制CD Rom中的所有文件并将它们保存在不同位置的文件夹中

Copying all files in CD Rom and saving them in a folder at a different location using win32 c++

在 win32 C++ 中有没有一种方法可以复制 CD Rom 中的所有文件并将它们保存在位于其他地方的文件夹中(将指定文件夹位置)?是否有 win32 C++ 函数可以执行此操作?文档显示函数 SHFileOperationA() 但这可以复制 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

您可以使用 FindFirstFile and FindNextFile combine with CopyFile.

假设你的光驱是E:,你可以试试下面的例子看看是否有帮助。

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);