zoukankan      html  css  js  c++  java
  • 删除文件夹下所有文件

    // 删除文件夹下的所有文件 VC6.0下测试通过
    BOOL DelDirFiles(CString strPath)
    {
    WIN32_FIND_DATA wfd;
    HANDLE hFind;
    CString strFullPath;
    CString strFindFilter;
    DWORD dwAttributes = 0;

    strFindFilter = strPath + _T("\*.*");
    hFind = FindFirstFile(strFindFilter, &wfd);
    if (INVALID_HANDLE_VALUE == hFind)
    {
    return FALSE;
    }

    do
    {
    if (_tcscmp(wfd.cFileName, _T(".")) == 0 ||
    _tcscmp(wfd.cFileName, _T("..")) == 0 )
    {
    continue;
    }

    strFullPath = strPath + _T("\") + wfd.cFileName;
    //去掉只读属性
    dwAttributes = GetFileAttributes(strFullPath);
    if (dwAttributes & FILE_ATTRIBUTE_READONLY)
    {
    dwAttributes &= ~FILE_ATTRIBUTE_READONLY;
    SetFileAttributes(strFullPath, dwAttributes);
    }

    if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    DelDirFiles(strFullPath);
    RemoveDirectory(strFullPath);
    }
    else
    {
    DeleteFile(strFullPath);
    }
    }while (FindNextFile(hFind, &wfd));

    FindClose(hFind);

    return TRUE;
    }

  • 相关阅读:
    排序算法分析
    图论算法小结
    A*算法
    分支界限法的应用
    图的搜索策略
    最大二分匹配
    C++学习笔记(1)
    vscode简单c语言多文件编译
    c语言变量大小
    十大排序算法总结
  • 原文地址:https://www.cnblogs.com/zengjunde/p/3485383.html
Copyright © 2011-2022 走看看