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\n", str.c_str());        

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

    _findclose(h);
}

 

转载于:https://www.cnblogs.com/vc60er/p/3929934.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#define _CRT_SECURE_NO_WARNINGS //顺序存储的栈 实现文件 ///////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct SeqStack { int* data; // 数据元素指针 int top; // 栈顶元素编号 int max; // 最大节点数 }SeqStack; /*创建一个栈*/ SeqStack* SS_Create(int maxlen) { SeqStack* ss = (SeqStack*)malloc(sizeof(SeqStack)); ss->data = (int*)malloc(maxlen * sizeof(int)); ss->top = -1; ss->max = maxlen; return ss; } /*释放一个栈*/ void SS_Free(SeqStack* ss) { free(ss->data); free(ss); } /*清空一个栈*/ void SS_MakeEmpty(SeqStack* ss) { ss->top = -1; } /*判断栈是否为满*/ int SS_IsFull(SeqStack* ss) { /*请在BEGIN和END之间实现你的代码*/ /*****BEGIN*****/ if (ss->top == ss->max - 1) return 1; return 0; /******END******/ } /*判断栈是否为空*/ int SS_IsEmpty(SeqStack* ss) { /*请在BEGIN和END之间实现你的代码*/ /*****BEGIN*****/ if (ss->top == -1) return 1; return 0; /******END******/ } /*将x进栈,满栈则无法进栈(返回0,否则返回1)*/ int SS_Push(SeqStack* ss, int x) { //务必看清楚使用的是C语言还是C++喔 /*请在BEGIN和END之间实现你的代码*/ /*****BEGIN*****/ /******END******/ } /*出栈,出栈的元素放入item,空栈则返回0,否则返回1*/ int SS_Pop(SeqStack* ss, int* item) { /*请在BEGIN和END之间实现你的代码*/ /*****BEGIN*****/ /******END******/ } /*从栈底到栈顶打印出所有元素*/ void SS_Print(SeqStack* ss) { if (SS_IsEmpty(ss)) { printf("stack data: Empty!\n"); return; } printf("stack data (from bottom to top):"); int curr = 0; while (curr <= ss->top) { printf(" %d", ss->data[curr]); curr++; } //printf("\n"); } int main() { int max; scanf("%d", &max); SeqStack* ss = SS_Create(max); char dowhat[100]; while (1) { scanf("%s", dowhat); if (!strcmp(dowhat, "push")) { int x; scanf("%d", &x); SS_Push(ss, x); } else if (!strcmp(dowhat, "pop")) { int item; SS_Pop(ss, &item); } else { break; } } SS_Print(ss); SS_Free(ss); }
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值