• Main
  • Forums
Home » Forums » Windows » Windows Server 2003

Cannot delete file: Cannot read from the source file or disk

miT's picture

miT —Fri, 05/29/2009 - 08:31

I’ve finally solved a problem that’s been bugging me for years. One of our file shares ended up with several undelete-able files. Attempting to delete them results in “Error Deleting File or Folder – Cannot delete file: Cannot read from the source file or disk“.

Even going to the file’s properties to check permissions presented a very blank properties dialog. And a CHKDSK didn’t sort thing out either.

It turns out the problem was: the filename ended with a dot, e.g. it was something like “C:\Temp\Stuff\Sales Agreement.“. As far as Windows is concerned this is an invalid file name: so although it gets reported in a directory listing, the standard Windows APIs for manipulating files subsequently deny its existence.

So how did this file get created in the first place? The answer: a Mac. The file was on a file share which had been accessed by a Mac user. Macs tend to write all sorts of metadata to extra “._DSStore” files and suchlike and had left this file behind.

So if Windows doesn’t appear to allow these file names, how did they get to be created? Well, it turns out that NTFS allows all sort of file name/path weirdness that Windows, or specifically the Win32 API, doesn’t allow. For example, NTFS actually allows file paths up to 32K but Windows restricts file paths to no more than 260 characters (MAX_PATH). I suppose this is all for DOS/Windows 9x backwards compatibility. As these files were being accessed over a file share I guess the usual Win32 checks are bypassed.

But thankfully you can get Win32 to ignore these checks by prefixing your file paths with \\?\, (ie. C:\Temp\SomeFile.txt becomes \\?\C:\Temp\SomeFile.txt) which I discovered after reading this blog post about long paths in .NET.

So at a command prompt I was able to delete the file using:

del "\\?\C:\Temp\Stuff\Sales Agreement."

If it’s a folder/directory you’re trying to delete use the rd or rmdir command, e.g.:

rd /s "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder."

Tip: as you’re typing the file/directory name use the TAB key to auto-complete the name (press TAB repeatedly to cycle through possible names).
Of course the corollary of all of this is that you could really annoy somebody by doing this:

echo Hi > "\\?\%USERPROFILE%\Desktop\Annoying file you can't delete."

But you wouldn’t do that would you?

  • Windows Server 2003
  • Add new comment
Anonymous's picture

Thanks for the help!

Submitted by Anonymous (not verified) on Fri, 01/21/2011 - 04:26

While I couldn't quite follow your fix for the problem, you did bring into light exactly what my problem was. The files I was trying to delete ended with a "." Realizing that was a no no, i tried deleting the old fashioned way. I went into the "command" prompt went to the directories containing the files, deleted each file manually, then deleted the directories. It worked and I thank you again for finding out about that nasty little "."

Joe

  • reply
Anonymous's picture

WOW thank you SOOOOOOOOO much

Submitted by Anonymous (not verified) on Fri, 04/08/2011 - 01:10

WOW

thank you SOOOOOOOOO much this TOTALLY worked. I downloaded a file that for some reason i could not move or delete. I am a total noob w/ computers but the command prompt entry:

rd /s "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder."

deleted the file immediately. (for other noobs like me out there: leave the quotations in the above AS IS. I thought you had to delete them, but nope leave them exactly like they are. Only change the path part (the C:\Documents and settings.... part).

  • reply
Anonymous's picture

Thanks for this. Fixed me

Submitted by Anonymous (not verified) on Sun, 09/18/2011 - 15:14

Thanks for this. Fixed me right up.

  • reply

Add new comment

The content of this field is kept private and will not be shown publicly.

More information about text formats

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
Are j00 a r0wb4wt?

New forum topics

  • willing to give a strong development
  • Windows Memory Testing Tool
  • WSUS Offline Windows Update
  • Windows Auto Start Locations
  • Make a Hidden User Account in XP / Vista / Win7
More

Active forum topics

  • willing to give a strong development
  • Windows Auto Start Locations
  • Top 9 tweaks for a faster (and less annoying) Vista PC
  • Cannot delete file: Cannot read from the source file or disk
  • Windows Memory Testing Tool
More

Recent comments

  • Wananaroiv 1 day 18 hours ago
  • Activation 2 months 1 week ago
  • Thanks for this. Fixed me 4 months 2 weeks ago
  • WOW thank you SOOOOOOOOO much 10 months 4 days ago
  • Problem with activation 11 months 3 weeks ago
  • Thanks for the help! 1 year 2 weeks ago
  • Dropbox is leet too! 2 years 9 months ago
  • internet explorer beta 8 3 years 3 months ago
  • w00t! 3 years 3 months ago

Search form

Navigation

  • Add content
  • Search
  • Recent content

User login

  • Create new account
  • Request new password

Who's online

There are currently 0 users online.

  • Main
  • Forums