VC删除文件夹下所有文件的代码

2016-02-19 20:12 1 1 收藏

图老师小编精心整理的VC删除文件夹下所有文件的代码希望大家喜欢,觉得好的亲们记得收藏起来哦!您的支持就是小编更新的动力~

【 tulaoshi.com - 编程语言 】

//删除文件夹目录(非空)

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

bool DeleteDirectory(char* sDirName)
{
    CFileFind tempFind;
    char sTempFileFind[200] ;
   
    sprintf(sTempFileFind,"%s*.*",sDirName);
    BOOL IsFinded = tempFind.FindFile(sTempFileFind);
    while (IsFinded)
    {
        IsFinded = tempFind.FindNextFile();
       
        if (!tempFind.IsDots())
        {
            char sFoundFileName[200];
            strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));
           
            if (tempFind.IsDirectory())
            {
                char sTempDir[200];
                sprintf(sTempDir,"%s%s",sDirName,sFoundFileName);
                DeleteDirectory(sTempDir);
            }
            else
            {
                char sTempFileName[200];
                sprintf(sTempFileName,"%s%s",sDirName,sFoundFileName);
                DeleteFile(sTempFileName);
            }
        }
    }
    tempFind.Close();
    if(!RemoveDirectory(sDirName))
    {
        return FALSE;
    }
    return TRUE;
}

/**//////////////////////////////////////////
//下面是应用,CString m_strDir 是一个文件夹路径,如:d:downloadpic

BOOL DelAll()
{
    if(PathFileExists(m_strDir))    
        DeleteDirectory((LPSTR)(LPCTSTR)m_strDir);
    return 1;
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

来源:https://www.tulaoshi.com/n/20160219/1623023.html

延伸阅读
微云文件夹删除方法   1)首先打开微云,进入首页,点击网盘按键,进入微云网盘界面,在按管理按键。   2)进入选择文件界面,选择好想删除的文件后,在点击删除按键。  
标签: ASP
       <%    set A=server.createobject("scripting.filesystemobject")    path="G:\count\0"    i=0    response.write "主目录:<br>"&path&"<ul>"    re    response.write "</li></ul>" '-----------------主目录...
代码如下: package com.xhkj.util; import java.io.File; import java.io.IOException; public class CreateFileUtil { public static boolean CreateFile(String destFileName) {     File file = new File(destFileName);     if (file.exists()) {      System.out.println("创建单...
标签: 电脑入门
在MAC电脑中搜索文件的时候,系统总是会默认在这台 Mac搜索,这样会浪费我们许多时间,如果我们确定要找的文件就是当前文件夹中,该如何设置电脑在当前文件夹搜索呢? 其实这个搜索的功能跟windows一样,也是可以设置的,在 Finder 偏好设置里调整: 现在用户们知道该如何设置MAC默认在当前文件夹搜索了吧,有了这个方法,以后再次搜索...
标签: ASP
       dir_name="abc"   Set fso = CreateObject("Scripting.FileSystemObject")   set self_path = fso.getfile(server.mappath(Request.ServerVariables("PATH_INFO")))   files_path=self_path.ParentFolder.ParentFolder   folderspec=files_path+"\"+dir_na...

经验教程

837

收藏

75
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部