1

Don't get me wrong: deleting a file is normally superfast.

However, if the file is in use, Windows will choke on it for exactly five seconds before displaying a message box indicating failure (access denied).

Windows XP Cannot delete: file in use

This is unacceptable in some cases, not mentioning the fact that it won't tell you which file is causing trouble. For example, if you need to delete a huge folder and some file deep down is blocking you, you'll most likely have to go on a long, boring quest to track him down.

Does anybody know why Windows XP takes so long to fail? If not, would there be a way to make it fail faster, or, at least, find out which files are open, and in what programs?

3
  • Use ProcMon from Sysinternals to figure it out. This question is way too broad to be answered in a meaningful way. May 10, 2012 at 13:19
  • 1
    Its amazing that 5 seconds is now way too long, how computers have changed our concept of time. I swear MS did all sorts of annoying things with patches in XP to nudge people towards upgrading to W7, that's my conspiracy theory.
    – Moab
    May 10, 2012 at 15:01
  • Nah, actually it's been way too long since 2000-something. This bug's been around forever, and has always bothered me. May 10, 2012 at 15:33

2 Answers 2

1

You can use the del and rmdir commands to delete files in a folder or a folder from cmd. You can force delete and ignore errors.

del /S /F /Q *
rmdir /S /Q <dir>

You can use a more advanced file browsers than Windows Explorer to delete files, like Total Commander. It's more user friendly for multiple selection of files and actions.

Then, for the files which can't be deleted, you can use ProcessExplorer (procexp.exe) from SysInternals package found free on the Internet. With Ctrl + F you can search for handles on specific files and objects. You just type in the file path of your file which cannot be deleted and you'll get the processes which access it.

6
  • What will "force delete" do when confronted with an open file? May 10, 2012 at 14:30
  • " /F Ignore read-only setting and delete anyway (FORCE)"
    – user127350
    May 10, 2012 at 14:55
  • At least it fails immediately. I still wonder why, through Explorer, it takes so long. May 10, 2012 at 14:59
  • 1
    Against my intuition, you are absolutely right about the SHIFT+DEL. It fails immediately! I'm really, really surprised. May 10, 2012 at 15:35
  • 1
    Ok, I'll consider that the procexp.exe tip answers my question. However I discovered something that I'll explain in another answer. May 10, 2012 at 16:12
1

Well, I discovered why Windows takes the exact five seconds.

I launched Process Monitor and filtered lines with the name of a test file I would try to delete (winplot.exe - sorry scientists). After the test, the log showed me that Windows XP tried to delete the file six times, with one second between each trial. You can see it clearly in the first column below:

18:02:37,59 Explorer.EXE QueryOpen                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:37,59 Explorer.EXE CreateFile                    D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:37,59 Explorer.EXE QueryAttributeTagFile         D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS Attributes: N, ReparseTag: 0x0
18:02:37,59 Explorer.EXE SetDispositionInformationFile D:\Documents and Settings\aneves\Desktop\winplot.exe CANNOT DELETE Delete: True
18:02:37,59 Explorer.EXE CloseFile                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:38,59 Explorer.EXE QueryOpen                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:38,59 Explorer.EXE CreateFile                    D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:38,59 Explorer.EXE QueryAttributeTagFile         D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS Attributes: N, ReparseTag: 0x0
18:02:38,59 Explorer.EXE SetDispositionInformationFile D:\Documents and Settings\aneves\Desktop\winplot.exe CANNOT DELETE Delete: True
18:02:38,59 Explorer.EXE CloseFile                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:39,59 Explorer.EXE QueryOpen                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:39,59 Explorer.EXE CreateFile                    D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:39,59 Explorer.EXE QueryAttributeTagFile         D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS Attributes: N, ReparseTag: 0x0
18:02:39,59 Explorer.EXE SetDispositionInformationFile D:\Documents and Settings\aneves\Desktop\winplot.exe CANNOT DELETE Delete: True
18:02:39,59 Explorer.EXE CloseFile                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:40,59 Explorer.EXE QueryOpen                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:40,59 Explorer.EXE CreateFile                    D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:40,59 Explorer.EXE QueryAttributeTagFile         D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS Attributes: N, ReparseTag: 0x0
18:02:40,59 Explorer.EXE SetDispositionInformationFile D:\Documents and Settings\aneves\Desktop\winplot.exe CANNOT DELETE Delete: True
18:02:40,59 Explorer.EXE CloseFile                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:41,59 Explorer.EXE QueryOpen                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:41,59 Explorer.EXE CreateFile                    D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:41,59 Explorer.EXE QueryAttributeTagFile         D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS Attributes: N, ReparseTag: 0x0
18:02:41,59 Explorer.EXE SetDispositionInformationFile D:\Documents and Settings\aneves\Desktop\winplot.exe CANNOT DELETE Delete: True
18:02:41,59 Explorer.EXE CloseFile                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:42,59 Explorer.EXE QueryOpen                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:42,59 Explorer.EXE CreateFile                    D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:42,59 Explorer.EXE QueryAttributeTagFile         D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS Attributes: N, ReparseTag: 0x0
18:02:42,59 Explorer.EXE SetDispositionInformationFile D:\Documents and Settings\aneves\Desktop\winplot.exe CANNOT DELETE Delete: True
18:02:42,59 Explorer.EXE CloseFile                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:42,59 Explorer.EXE CreateFile                    D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:42,59 Explorer.EXE QueryAttributeTagFile         D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS Attributes: N, ReparseTag: 0x0
18:02:42,59 Explorer.EXE SetDispositionInformationFile D:\Documents and Settings\aneves\Desktop\winplot.exe CANNOT DELETE Delete: True
18:02:42,59 Explorer.EXE CloseFile                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS
18:02:42,59 Explorer.EXE QueryOpen                     D:\Documents and Settings\aneves\Desktop\winplot.exe SUCCESS

I don't know what to make of this programming choice, except that it appears rather dumb to me at first sight -- sorry, Microsoft, I'm being really honest here.

* EDIT: to be rigorous, it tries to delete seven times, but the last time immediately follows the former

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .