请问在VC中如何实现将一个文件拷贝到指定的目录中,如何删除指定的目录或文件;能提供代码的最好,谢谢!

解决方案 »

  1.   

    拷贝文件用CopyFile即可,如CopyFile("D:\\abc.txt", "e:\\Bk\\cc.txt",TRUE);删除文件用DeleteFile;如DeleteFile("d:\\abc.txt");对于直接删除文件夹,我没见到,,,对不起了
      

  2.   

    下面的代码首先把c:\test.txt拷到c:\dir1目录里,然后删除c:\dir1目录 SHFILEOPSTRUCT fo;
    fo.hwnd = NULL;
    fo.pFrom = "c:\\test.txt\0";
    fo.pTo = "c:\\dir1\0";
    fo.wFunc = FO_COPY;
    fo.fFlags = 0;
    SHFileOperation(&fo); fo.fFlags = FOF_NOCONFIRMATION;
    AfxMessageBox("press enter to delete the folder");
    fo.pFrom = fo.pTo;
    fo.wFunc = FO_DELETE;
    SHFileOperation(&fo);
      

  3.   

    6, 删除文件夹及包含的文件
    #include <direct.h>
    void DeleteDirFile(CString sPath)
    {
    WIN32_FIND_DATA fd;
    HANDLE hFind = ::FindFirstFile(sPath + "*.*",&fd);

    if (hFind != INVALID_HANDLE_VALUE)
    {
    while (::FindNextFile(hFind,&fd))
    {
    //判断是否为目录
    if (fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
    {
    CString name;
    name = fd.cFileName;
    //判断是否为.和..
    if ((name != ".") && (name != ".."))
    {
    //如果是真正的目录,进行递归
    DeleteDirFile(sPath + fd.cFileName + "\\");
    }
    }
    else
    DeleteFile(sPath + fd.cFileName);
    }
    ::FindClose(hFind);
    }
    RemoveDirectory(sPath);
    }