從剪貼板上獲得要複製/剪貼的文件路徑之後,如何完成文件/文件夾的粘貼呢。下面列出了兩個函數用來完成這些功能
- //複製的粘貼
- DWORD VrvCopyFile( LPCWSTR lpSrc, LPCWSTR lpDst )
- {
- DWORD dwError = 0;
- CString strFiles = lpSrc;
- CString strFilePath = _T("");
- int idx= 0;
- while (strFiles.Find('#',idx) != -1)
- {
- int y = strFiles.Find('#',idx);
- strFilePath = strFiles.Mid(idx,y - idx);
- TCHAR szFile[MAX_PATH] = {0};
- lstrcpy(szFile,strFilePath.GetBuffer());
- strFilePath.ReleaseBuffer();
- idx = strFiles.Find('#',idx);
- idx++;
- SHFILEOPSTRUCT shFileOp = {0};
- shFileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
- shFileOp.pFrom = szFile;
- shFileOp.pTo = lpDst;
- shFileOp.wFunc = FO_COPY;
- dwError = SHFileOperation(&shFileOp);
- }
- return dwError;
- }
- //剪貼的粘貼
- DWORD VrvMoveFile(LPCWSTR lpSrc, LPCWSTR lpDst)
- {
- DWORD dwError = 0;
- CString strFiles = lpSrc;
- CString strFilePath = _T("");
- int idx= 0;
- while (strFiles.Find('#',idx) != -1)
- {
- int y = strFiles.Find('#',idx);
- strFilePath = strFiles.Mid(idx,y - idx);
- TCHAR szFile[MAX_PATH] = {0};
- lstrcpy(szFile,strFilePath.GetBuffer());
- strFilePath.ReleaseBuffer();
- idx = strFiles.Find('#',idx);
- idx++;
- SHFILEOPSTRUCT shFileOp = {0};
- shFileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
- shFileOp.pFrom = szFile;
- shFileOp.pTo = lpDst;
- shFileOp.wFunc = FO_MOVE;
- dwError = SHFileOperation(&shFileOp);
- }
- return dwError;
- }
源路徑存放了多個文件路徑,使用#分開,每個文件/文件夾逐個粘貼。