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;
    }

  • 相关阅读:
    032 代码复用与函数递归
    031 实例7-七段数码管绘制
    030 函数的定义与使用
    029 函数和代码复用
    2.4 Buffer
    2.3 字符串链接
    2.2 去除字符串特别字符
    2.1 字符串查询
    存储数据_文件读写
    template模板
  • 原文地址:https://www.cnblogs.com/zengjunde/p/3485383.html
Copyright © 2011-2022 走看看