On Windows is there an interface for Copying Folders?

前端 未结 7 564
陌清茗
陌清茗 2021-01-18 06:41

I want to copy folder A and paste to desktop.

I am currently using C++ so preferably an OO interface if available.

7条回答
  •  抹茶落季
    2021-01-18 07:17

    Use this

    bool CopyDirTo( const wstring& source_folder, const wstring& target_folder )
    {
        wstring new_sf = source_folder + L"\\*";
        WCHAR sf[MAX_PATH+1];
        WCHAR tf[MAX_PATH+1];
    
        wcscpy_s(sf, MAX_PATH, new_sf.c_str());
        wcscpy_s(tf, MAX_PATH, target_folder.c_str());
    
        sf[lstrlenW(sf)+1] = 0;
        tf[lstrlenW(tf)+1] = 0;
    
        SHFILEOPSTRUCTW s = { 0 };
        s.wFunc = FO_COPY;
        s.pTo = tf;
        s.pFrom = sf;
        s.fFlags = FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NO_UI;
        int res = SHFileOperationW( &s );
    
        return res == 0;
    }
    

提交回复
热议问题