#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
if( _mkdir( "\\testtmp" ) == 0 )
{
printf( "Directory '\\testtmp' was successfully created\n" )
system( "dir \\testtmp" )
if( _rmdir( "\\testtmp" ) == 0 )
printf( "Directory '\\testtmp' was successfully removed\n" )
else
printf( "Problem removing directory '\\testtmp'\n" )
}
else
printf( "Problem creating directory '\\testtmp'\n" )
}
BOOL SelPackDirDlg::CreateMultiFolder(CString cstrPath){
BOOL bRet = TRUE
LPCSTR lpcstrParent
CString cstrParent
int iPos = 0
int iLen
if(cstrPath.IsEmpty()) return FALSE
iLen = cstrPath.GetLength()
iPos = cstrPath.ReverseFind('\\')
cstrParent = cstrPath.Left(iPos)
if(cstrParent.IsEmpty()) return FALSE // 目录名称错误
lpcstrParent = cstrParent.Left(cstrParent.GetLength())
if(cstrParent.GetLength() > 3) // 如果长度小于3,表示为磁盘根目录
bRet = IsExistDirectory(lpcstrParent)// 检查父目录是否存在
if(!bRet)
bRet = CreateMultiFolder(lpcstrParent) // 父目录不存在,递归调用创建父目录
if(bRet){ // 父目录存在,直接创建目录
bRet = CreateDirectory(cstrPath, NULL)
}
return bRet
}
BOOL SelPackDirDlg::IsExistDirectory(CString cstrPath)
{
BOOL bExist
WIN32_FIND_DATA wfd // 查找
HANDLE hFind = FindFirstFile(cstrPath, &wfd)
if(hFind == INVALID_HANDLE_VALUE) {// 没有找到配备,目录肯定不存在
bExist = FALSE
}
else{ // 检查找到的结果是否目录
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
bExist = TRUE // 存在,是目录
else
bExist = FALSE // 存在,不是目录
FindClose(hFind)
}
return bExist
}//****************************** End. ************************/
基本思路是这样的,可以按个人要求定做
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)