从剪贴板上获得要复制/剪贴的文件路径之后,如何完成文件/文件夹的粘贴呢。下面列出了两个函数用来完成这些功能
- //复制的粘贴
- 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;
- }
源路径存放了多个文件路径,使用#分开,每个文件/文件夹逐个粘贴。
本文出自 “麻雀的家” 博客,请务必保留此出处http://3457302.blog.51cto.com/3447302/902593