MFC 创建文件夹(时间命名)

    //E盘根目录创建以时间命名的文件夹,其中再建4个子文件夹
    CString strTime = CTime::GetCurrentTime().Format("%Y%m%d");//获取当前时间
    CString strPath = _T("E:\\" + strTime);//路径
    if (!PathIsDirectory(strPath))//不存在则创建
    {
        CString strMsg = strPath + _T("不存在,是否创建?");
        if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
        {
            CreateDirectory(strPath, NULL);//创建主文件夹

            CString strPath1 = strPath + _T("\\up");
            CString strPath2 = strPath + _T("\\down");
            CString strPath3 = strPath + _T("\\left");
            CString strPath4 = strPath + _T("\\right");
            if (PathIsDirectory(strPath))//主文件夹存在,创建子文件夹
            {
                CreateDirectory(strPath1, NULL);
                CreateDirectory(strPath2, NULL);
                CreateDirectory(strPath3, NULL);
                CreateDirectory(strPath4, NULL);
                return;
            }
        }
    }
    return;

猜你喜欢

转载自www.cnblogs.com/xixixing/p/12144109.html