c++ - Delete a file instead of marking it for deletion -
i writing service windows (from xp 8.1). need recursively delete folder , use deletefile , removedirectory that. don't want use shfileoperation because has max_path limit.
the problem sometimes, removedirectory fails error_dir_not_empty, if directory empty. found out because deletefile works asynchronously, "marks" file deletion. therefore, adding small delay (sleep) before calling removedirectory fixes issue. looking cleaner method.
so, there way ensure marked files , deleted?
i tried call flushfilebuffers directly on directory, without success.
edit: claiming ntdeletefile can delete file if there handles open on it. checked , it's wrong, @ least on windows 8.1: file removed when handles closed.
i don't want use shfileoperation because has max_path limit.
on vista+, can (and should) use ifileoperation instead of shfileoperation(). not limited path length limitations, , can used safely in service, unlike shfileoperation():
is wrong call shfileoperation service?
is wrong call shfileoperation service? revised
so decided call shfileoperation service, @ least remember disable copy hooks
so, there way ensure marked files , deleted?
not really. files either in use, or not cleared cache manager, or like. if deletefile() succeeds, know file deleted eventually. have give system time actually delete it. if receive error_dir_not_empty, wait few seconds , try again. if keep getting error_dir_not_empty after several attempts, either fail operation since folder not ready deleted yet, or else keep trying until succeeds, enumerating files periodically (in case new files created).
Comments
Post a Comment