windows CopyFile的正确输入格式是什么

What is the correct input format for windows CopyFile?

本文关键字:输入 格式 是什么 CopyFile windows      更新时间:2023-10-16

我正在尝试使用windows CopyFile函数复制一个文件,并将其重命名为其他文件夹中的另一个文件。然而,它总是返回路径有问题,即使我给它的路径是正确的,并且文件和文件夹都存在。我做错了什么?

使用"C:\Dummy.png"作为源,使用"C:\Dest"作为目标。

void CreateDummyItemsAssetsPNG()
{
    string  DummyAsset;  
    string  dummyDestination; 
    cout<<"Please Provide dummy file asset that is a .png: "; 
    cin>>DummyAsset; 
    cout<<"Please Provide a Destination: "; 
    cin>>dummyDestination; 
    vector<string>::iterator itor; 
    string fullDest; 
    for(itor = listOfItems.begin(); itor<listOfItems.end(); ++itor)
    {
        fullDest.clear(); 
        fullDest = dummyDestination + "\"+ (*itor)+".png"; 
        cout<<"Copy: "<<DummyAsset<<" TO: "<<fullDest<<endl; 
        if(!CopyFile(LPCTSTR(DummyAsset.c_str()),LPCTSTR(dummyDestination.c_str()),false) )
        {
            printf("Could not copy file.n"); 
            cout<<GetLastError()<<endl; 
        }
    }
}

谢谢!

CopyFile()需要一个文件名称作为第二个参数,而您只传递目标目录。指定全名(您似乎在fullDest中这样做),这应该会起作用。