Thursday, September 3, 2009

"Cannot read from the source file or disk" error when deleting

I've run into the "Cannot read from the source file or disk" problem more than once, and every time it had has to do with trying to delete a file originally created by a Mac from a Windows-based file server. I used to just leave the file in place, but I finally couldn't take it anymore and found a solution: It appears that the issue is caused by the files ending in a hidden period, which NTFS systems can not read. However, Windows is able to delete it, but it must be done from the command line and requires you to know a special set of characters ("\\?\") to use as a prefix to the file path.

For an example, let's say I get this error on a file with a path C:\myfile.txt. In order to delete myfile.txt, I would have to open a command prompt. From there I would use the command

del "\\?\C:\myfile.txt"

This would remove the problematic file from the system. You can also use this with folders

rmdir /s "\\?\C:\myfolder"

There the rmdir /s will recursively remove all files/folders within the specified folder, and then delete the folder itself. Without using the /s switch, you would have to manually remove all files and folders within the folder you're trying to delete first.

No comments: