Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/65601998/copying-all-files-in-cd-rom-and-saving-them-in-a-folder-at-a-different-location

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...