zoukankan      html  css  js  c++  java
  • 文件夹操作

    int CCorreDataMain::IsDirectoryFind(CString szPath)//文件夹是否存在 0存在 -1为空,-2为非法路径,-3为盘符异常,-4需要创建目录
    {
    if (szPath == "") return -1;//为空
    if (szPath.Right(1)=='//') szPath.TrimRight('//');//去掉
    if (szPath.GetLength()<2)
    return -2;//非法路径
    else if (szPath.GetLength()==2)
    {
    szPath.MakeUpper();
    TCHAR aa = szPath.GetAt(0);
    if ((aa>='A')&&(aa<='Z'))
    {
    DWORD dwDrivers = GetLogicalDrives();
    DWORD dwMask = 1<<(aa-'A');
    if (dwMask & dwDrivers)
    {
    return 0;//盘符存在;
    }else
    return -3;//盘符异常
    }
    else
    return -3;//盘符异常
    }else
    {
    CFileFind ff;
    BOOL bExist = ff.FindFile(szPath);
    if (!bExist)//目录不存在
    {
    return -4;//需要创建新目录
    }
    }
    return 0;
    }
    BOOL CCorreDataMain::CheckPath(CString &szPath,BOOL bCanCreateDir,BOOL bDirectory)//检查路径是否有问题
    {
    if (bDirectory)//如果路径是目录的话
    {
    switch(IsDirectoryFind(szPath))
    {
    case -1:
    AfxMessageBox(_T("目录不能为空!"));
    return FALSE;
    break;
    case -2:
    AfxMessageBox(_T("非法路径!"));
    return FALSE;
    break;
    case -3:
    AfxMessageBox(_T("盘符异常!"));
    return FALSE;
    break;
    case -4:
    if (szPath.Right(1)=='//') szPath.TrimRight('//');
    if (bCanCreateDir)//如果目录不存在是否自动创建?
    {
    if (!CreateDirectory(szPath,NULL))
    {
    AfxMessageBox(_T("文件夹创建失败!"));
    return FALSE;
    }
    }
    break;
    }
    if (szPath.Right(1)=='//') szPath.TrimRight('//');
    }else
    {//路径是文件的话
    CString szTmp = szPath;
    int nLen = szTmp.GetLength();
    szTmp = szTmp.Left(szTmp.ReverseFind('//') +1);
    if (!CheckPath(szTmp,bCanCreateDir,TRUE))
    {
    //路径有问题
    AfxMessageBox(szTmp+_T("路径有问题!"));
    return FALSE;
    }
    CFileFind ff;
    if (!ff.FindFile(szPath))
    { //文件不存在
    ff.Close();
    return FALSE;
    }
    }
    return TRUE;
    }


    BOOL CCorreDataMain::CheckFileSize(CString szFile,LONG lLen)
    {
    CFile tmpfile;
    if (!tmpfile.Open(szFile,CFile::typeBinary|CFile::modeRead))
    {
    return FALSE;
    }
    LONG lLength;
    lLength = tmpfile.GetLength();
    tmpfile.Close();
    if (lLength!=lLen) return FALSE;
    return TRUE;
    }
  • 相关阅读:
    教务管理系统(node+express+mysql)
    poj 2485 Highways 超级大水题 kruscal
    HDU 1874 畅通工程续 + HDU 2544 最短路 最短路水题,floyd水
    HEX格式转BIN格式 MOT格式转BIN格式
    html的标签一共有多少个?
    同时存在n个线程(n>5),需要写入或者读取一个名为test.txt的文件
    poj 1258 AgriNet 水题三连发。。。又是kruscal
    招投标专家库
    poj 1789 kruscal水题
    仿Word自动套用格式,用CSS设置表格样式
  • 原文地址:https://www.cnblogs.com/carl2380/p/2317356.html
Copyright © 2011-2022 走看看