Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Use ProcMon from Sysinternals to figure it out. This question is way too broad to be answered in a meaningful way. –  0xC0000022L May 10 '12 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 '12 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. –  André Neves May 10 '12 at 15:33

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
What will "force delete" do when confronted with an open file? –  André Neves May 10 '12 at 14:30
    
" /F Ignore read-only setting and delete anyway (FORCE)" –  Radoo May 10 '12 at 14:55
    
At least it fails immediately. I still wonder why, through Explorer, it takes so long. –  André Neves May 10 '12 at 14:59
    
Are you press Shift + DEL or just DEL to delete? I have no clue if it could have any relation to the fact with DEL key, files go to Recycle Bin, but you can give it a go. –  Radoo May 10 '12 at 15:05
    
Against my intuition, you are absolutely right about the SHIFT+DEL. It fails immediately! I'm really, really surprised. –  André Neves May 10 '12 at 15:35

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.