한 걸음씩..

Create_Directory / Directory_Copy / File_Remove 본문

프로그래밍

Create_Directory / Directory_Copy / File_Remove

smdy0426 2013. 7. 15. 10:57
반응형

BOOL Create_Directory( WCHAR* Path )

{

BOOL bRet = FALSE;

WCHAR DirName[MAX_PATH];

WCHAR* p = Path;

WCHAR* q = DirName;

while(*p)

{

if( ('\\' == *p) || ('/' == *p))

{

if(':' != *(p-1))

{

bRet = CreateDirectory(DirName, NULL);

if(!bRet)

return bRet;

}

}

*q++ = *p++;

*q = '\0';

}

bRet = CreateDirectory(DirName, NULL);

return bRet;

}

////////////////////////////////////////////////////////////


BOOL Directory_Copy( CString dest_path, CString src_path )

{

if( dest_path.IsEmpty() )    

return FALSE;


CString argc = _T("\"") + dest_path + _T("\"\\*.* ") + _T("\"") + src_path + _T("\" /e /h");

SHELLEXECUTEINFO info = {0};

info.hwnd = NULL;

info.cbSize = sizeof(info);

info.lpFile = _T("c:\\windows\\system32\\xcopy.exe");

info.lpParameters = argc;

info.lpVerb = _T("open");

info.lpDirectory = NULL;

info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI ;

info.nShow = SW_HIDE;


int nResult = (int)ShellExecuteEx(&info);

if (nResult == 0)

return FALSE;

else

WaitForSingleObject (info.hProcess, INFINITE);


    return TRUE;

////////////////////////////////////////////////////////////


BOOL File_Remove( CString strPath )

{

BOOL bRet = FALSE;


if( strPath.IsEmpty() )

return FALSE;


CString strNextDirPath = _T("");

CString strRootPath = _T("");

CFileFind ff;


bRet = ff.FindFile(strPath);

if(bRet == FALSE) return bRet;


while (bRet)

{

bRet = ff.FindNextFile();

if( ff.IsDots() == TRUE ) continue;


if(ff.IsDirectory())

{

strNextDirPath.Format(L"%s\\*.*", ff.GetFilePath());

WorkFileRemove(strNextDirPath);

}

else

{

DeleteFile(ff.GetFilePath());

}

}

strRootPath = ff.GetRoot();

ff.Close();

bRet = RemoveDirectory(strRootPath);

return bRet;

}

반응형