另存文件时使用 copyfile("data.txt", "d:\aaa.txt", TRUE) 为何总是返回0值,说复制失败了。data.txt文件在默认的目录下。

解决方案 »

  1.   

    看它的第三个参数,估计是文件已经存在了
    bFailIfExists 
    [in] Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds
      

  2.   

    copyfile("data.txt", "d:\\aaa.txt", TRUE) 
    转义字符
      

  3.   

    copyfile("data.txt", "d:\\aaa.txt", TRUE) 这个文件你的源目录是在哪里????
      

  4.   

    copyfile("data.txt", "d:\\aaa.txt", TRUE) data.txt这个文件你的源目录是在哪里????
      

  5.   

    源文件就在当前程序文件所在的目录。目的目录好像有问题,上面说的转义字符问题确实对。我要求这样实现:
    CFileDialog fileDlg(FALSE, "ST", NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
    "文件类型(*.ST)|*.ST|", NULL);
    CString csTemp;
    if (fileDlg.DoModal() == IDOK) {
        csTemp = fileDlg.GetFileName();
    }
    copyfile("data.txt", csTemp, TRUE);
    我发现只有复制到当前目录时才能正确执行
      

  6.   

    对了,转义字符问题我已经处理了
    csTemp.Replace("\\", "\\\\");
      

  7.   

    当前目录是在不断变化的。 虽然程序刚启动时与exe文件所在目录相同,但当你用CFileDialog等,切换到其它目录时,当前目录就变了。
    因此最后给它一个全路径。