c++ - How to delete folder containing files and sub folder properly in a MFC application -
i have mfc application facing problem folder delete. when deleting folder along containing files, shows deleted application file list shows in windows explorer remains not-accessible.when close application folder vanishes windows explorer. why happening? have seen removedirectory()
in following code returning zero. if not deleted, why goes away after closing application. function follows:
void someclass::deletefilefolder(cstring filepath) { cfilefind finder; cstring strwildcard(filepath); strwildcard += _t("\\*.*"); cstring str = ""; bool bworking = finder.findfile(strwildcard); while (bworking) { bworking = finder.findnextfile(); if (finder.isdots()) { cstring sfile = finder.getfilename(); if(sfile !="." && sfile !="..") { cstring sfile = finder.getfilename(); str = finder.getfilepath(); bool bdel = deletefile(str); } } else if (finder.isdirectory()) { cstring sdir = finder.getfilename(); str = finder.getfilepath(); if((str !=".") && (str !="..") && (str != ".svn")) { deletefilefolder(str); bool bdel = removedirectory(str); } } else { cstring sfile = finder.getfilename(); str = finder.getfilepath(); bool bdel = deletefile(str); } } bool bdel = removedirectory(filepath); finder.close();
}
please guide.
sounds open handle file/folder that's not closed until termination or perhaps it's somehow set current working folder application.
did consider using shfileoperation instead? you're reinventing wheel.
shfileopstruct shfo = { null, fo_delete, path, null, fof_silent | fof_noerrorui | fof_noconfirmation, false, null, null }; shfileoperation(&shfo);
the "path" variable needs doubly null terminated.
Comments
Post a Comment