Files
2022-10-26 12:25:11 +08:00

94 lines
1.9 KiB
C++

#include ".\myfolder.h"
#include "shellapi.h"
#include "shlwapi.h"
#include "stdio.h"
MyFolder::MyFolder(void)
{
}
MyFolder::~MyFolder(void)
{
}
BOOL MyFolder::CopyFoler( const TCHAR* pszFrom, const TCHAR* pszTo )
{
//먼저 pszTo 폴더의 디렉토리를 생성한다.
CreteFolder( pszTo );
TCHAR fromPath[MAX_PATH+2];
memset(fromPath, 0, sizeof(fromPath));
strcpy(fromPath, pszFrom);
TCHAR toPath[MAX_PATH+2];
memset(toPath, 0, sizeof(toPath));
strcpy(toPath, pszTo);
SHFILEOPSTRUCT shfo = {0};
ZeroMemory(&shfo, sizeof shfo);
shfo.hwnd = NULL;
shfo.wFunc = FO_COPY;
shfo.fFlags = FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION;
shfo.lpszProgressTitle = "폴더 복사";
shfo.fAnyOperationsAborted = false;
shfo.pTo = toPath;
shfo.pFrom = fromPath;
int nResult = SHFileOperation(&shfo);
if( nResult == 0 ) return TRUE;
return FALSE;
}
BOOL MyFolder::DeleteFoler( const TCHAR* pszPath )
{
BOOL bRet = TRUE;
SHFILEOPSTRUCT *SHELL = new SHFILEOPSTRUCT;
memset( (void*)SHELL,0,sizeof(SHFILEOPSTRUCT) );
char buff[255];
memset(buff,'\0',sizeof(buff));
sprintf(buff, "%s\0\0", pszPath ); //2개 넣는게 중요..
SHELL->wFunc = FO_DELETE;
SHELL->pFrom = buff;
SHELL->fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION;
if( strstr( pszPath, "*") ) //wild card
{
SHELL->fFlags |= FOF_FILESONLY;
SHELL->fFlags |= FOF_MULTIDESTFILES;
}
if( SHFileOperation(SHELL) != 0) bRet = FALSE;
delete SHELL;
return bRet;
}
void MyFolder::CreteFolder( const TCHAR* pszFoletPath )
{
int len = (int)strlen(pszFoletPath) + 1;
char *buf = new char[len];
strcpy(buf, pszFoletPath);
for(int idx = 0; idx < len; idx++)
{
if(buf[idx] && buf[idx] != '\\')
continue;
buf[idx] = '\0';
if(PathIsDirectory(buf) == FALSE)
CreateDirectory(buf, NULL);
buf[idx] = '\\';
}
delete[] buf;
}