Getting rid of nul, or: How I learnt to love UNC (29 Apr 2006)

Every now and then, some tool on my system runs berserk and starts to generate files called nul. This is a clear indication that there's something going wrong with output redirection in a script, but I still have to figure out exactly what's going on. Until then, I need at least a way to get rid of those files.

Yes, that's right, you cannot delete a file called nul that easily - neither using Windows Explorer nor via the DOS prompt. nul is a very special filename for Windows - it is an alias for the null device, i.e. the bit bucket where all the redirected output goes, all those cries for help from software which we are guilty of ignoring all the time.

UNC path notation to the rescue: To remove a file called nul in, say c:\temp, you can use the DOS ren and del commands as follows:

  ren \\.\c:\temp\nul foobar
  del foobar

Because I always forget the exact UNC syntax, I came up with the following naïve batch file which does the job for me. Usage: delnul x:\some\path\nul.

@echo off
set fullpath=
for %%i IN (%1x) DO set fullpath=%%~di%%~pi

set filename=
for %%i IN (%1x) DO set filename=%%~ni

if "x%filename%" == "xnulx" goto :deletenul
echo This script is only meant to be used for "nul" files.
goto :end

:deletenul:
echo Deleting %fullpath%nul...
ren \\.\%fullpath%nul wasnul && del \\.\%fullpath%wasnul

:end

DelinvFile seems to take this a little further; it has a Windows UI and can delete many other otherwise pretty sticky files - nul is not the only dangerous file names; there's con, aux, prn and probably a couple of other magic names which had a special meaning for DOS, and hence also for Windows.



When asked for a TWiki account, use your own or the default TWikiGuest account.



to top

You are here: Blog > BlogOnSoftware20060429

r1.2 - 29 Apr 2006 - 13:12 - ClausBrod to top

Blog
This site
RSS

  2017: 12 - 11 - 10
  2016: 10 - 7 - 3
  2015: 11 - 10 - 9 - 4 - 1
  2014: 5
  2013: 9 - 8 - 7 - 6 - 5
  2012: 2 - 10
  2011: 1 - 8 - 9 - 10 - 12
  2010: 11 - 10 - 9 - 4
  2009: 11 - 9 - 8 - 7 -
     6 - 5 - 4 - 3
  2008: 5 - 4 - 3 - 1
  2007: 12 - 8 - 7 - 6 -
     5 - 4 - 3 - 1
  2006: 4 - 3 - 2 - 1
  2005: 12 - 6 - 5 - 4
  2004: 12 - 11 - 10
  C++
  CoCreate Modeling
  COM & .NET
  Java
  Mac
  Lisp
  OpenSource
  Scripting
  Windows
  Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home



Jump:

Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback