zoukankan      html  css  js  c++  java
  • c/c++常用代码--清空目录

    #pragma once

    #include <io.h>
    #include <stdio.h>
    #include <string>
    #include <direct.h>


    static void clean_dir(const char* szDir)
    {
        if (szDir == NULL || strlen(szDir) == 0)
            return;

        std::string strDir = szDir;

        char c = strDir[strDir.length() - 1];
        if (c != '/' && c != '\')
            strDir += '/';

        struct _finddata_t fd;
        long h=_findfirst((strDir + "*.*").c_str(), &fd);
        if (h == -1)
        {
            return ;
        }

        do
        {
            if (strcmp(fd.name, ".") == 0
                || strcmp(fd.name, "..") == 0)
                continue;

            if (fd.attrib & (_A_SYSTEM | _A_HIDDEN))
                continue;

            if (fd.attrib & _A_SUBDIR)
            {
                std::string str = strDir + fd.name + "/";
                clean_dir(str.c_str());
                rmdir(str.c_str());
                continue;
            }
            
            std::string str = strDir + fd.name;
            printf("%s ", str.c_str());        

            remove(str.c_str());
        }
        while (_findnext(h, &fd)==0);

        _findclose(h);
    }

  • 相关阅读:
    Linux用户空间与内核地址空间
    [Linux内存]——内核地址空间
    使用 GDB 调试多进程程序
    Linux GDB常用命令
    GDB常用命令使用
    GDB调试原理——ptrace系统调用
    不可见乱码 怎么消除
    Vue use的理解
    Element-UI 下边框,表格错位问题
    sort 排序传递更多参数
  • 原文地址:https://www.cnblogs.com/vc60er/p/3929934.html
Copyright © 2011-2022 走看看