c++ - Access denied when repeatedly create and remove the same directory -
i had little test, , how did it:
repeatedly create , remove 1 directory, d:\test, example. did 1000 times, , error acccessing denied time.
my code wrote this:
tchar szerror[max_path] = {0}; tchar lpszpath[max_path] = _t("d:\\test"); for(int = 0; != 1000; i++) { if (!createdirectory(lpszpath, null)) { formatmessage(format_message_from_system, null, getlasterror(), null, szerror, max_path, null); messagebox(null, szerror, _t("create directory error"), mb_ok); cout << << endl; return 0; } setfileattributes(lpszpath, file_attribute_normal); if (!removedirectory(lpszpath)) { formatmessage(format_message_from_system, null, getlasterror(), null, szerror, max_path, null); messagebox(null, szerror, _t("remove directory error"), mb_ok); cout << << endl; return 0; } }
can please tell me why error happened , how can avoid error?
if speed issue, consider using sleep function between each create/delete.
Comments
Post a Comment