Tuesday, February 09, 2010

Deleting a file called "nul" in Windows 7

I tried to use "nul" instead of "/dev/null" in Cygwin. That created a file called "nul". When I tried to delete the file in Explorer, I got an interesting "Invalid MS-DOS function" error:


The file can be deleted (and otherwise manipulated) from Cygwin. It can also be deleted from the Windows Command Prompt by prefixing its full path with "\\?\".

11 comments:

toomanyjoes said...

You're a genius. Any idea why this prefix works? What it means? I finally completely removed cygwin, other useful commands for removing locks and folders for which the user has no permission.

C:\>takeown /f sendmail.lnk && icacls sendmail.lnk /grant {USERNAME}:F

or for all files in a folder

C:\>takeown /f * /r /d y && icacls * /grant {USERNAME}:F /t

Unknown said...

you are the best this was driving me crazy!! Thanks :D

Anonymous said...

Thanks for making this info available. But what does \\?\ mean?

Boris Gjenero said...

"For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system."

Anonymous said...

Thank's a lot :D ! (From Italy)

Nicolas said...

Merci beaucoup (thanks a lot) from France.

I was encountering this problem developping with eclipse (one of my program just created a file starting by "null" ...)

hajush said...

Thanks! Still useful!

CEO'Riley said...

Thanks. It was driving me crazy.

Unknown said...

i tried doing the same but im get an access denied message

Unknown said...

actually i used folder lock to lock some files.It was only a trail version and expired after some days. Then i couldn't open the locked files.So i uninstalled folder lock. All the files i locked had NUL.prefix . Any other solution? coz i tried the \\?\ prefixing it only gave me a access denied message

Boris Gjenero said...

The fact you're getting "access denied" instead of "could not find" means you entered the right string for the file, but something else is stopping you. Maybe the file has the read-only attribute. Try "del /f" which overrides that. If a file had hidden, system and read-only attributes, you could use "del /a /f". If you still get access denied, there may be a permissions issue, and you should try again from a command prompt running as Administrator.