删除目录的功能只有在调试完成c ++之后才会删除它 [英] Function to remove directory removes it only after debug finishes c++

查看:145
本文介绍了删除目录的功能只有在调试完成c ++之后才会删除它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码在c ++中删除包含文件的目录:

I have this code in c++ to remove directory that includes files in it:

void*  hFind = INVALID_HANDLE_VALUE;
        WIN32_FIND_DATA ffd;

        hFind = FindFirstFile((fullpath+"\\" + _docname + "\\"+"*").c_str(), &ffd);

        do //delete all the files in the directory
        {
            // check if it is a file
            if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
            {
                string s = (fullpath+_docname+"\\").append(ffd.cFileName);
                remove(s.c_str());
            }
        }
        while (FindNextFile(hFind, &ffd) != 0);
        removeDirectory(fullpath+"\\" + _docname);      
        FindClose(hFind);

问题是 - 目录实际上是在我关闭发布器后才删除。
调试时,目录不可访问,但仍然存在,它让我烦恼。
你知道如何修复它tottaly删除文件夹?

The problem is - the directory is actually removed only after I close the dubugger. While debugging, the directory is inaccessible, but still exists, and it make me troubles. Do you know how can I fix it to tottaly remove the folder?

推荐答案

交换最后两行可能会修复这个:在删除目录之前关闭句柄

swapping the last two lines might fix this: close the handle before removing the directory

FindClose( hFind );
removeDirectory( fullpath + "\\" + _docname );       

这篇关于删除目录的功能只有在调试完成c ++之后才会删除它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆