Thanks
dougcranston.
It just so happened that I ran across NET FILE nnn /CLOSE while looking for something else a couple days ago.
I wrote a nice VBScript to do it too, but it is sort of thrash-o-rama as it runs the NET FILE and then each NET FILE nnn /CLOSE via WScript.Exec. This means each run pops up a separate command window briefly: flicker, flicker, flicker! I used Exec because it avoids having to create temporary files containing redirected output. This has its own drawbacks though, I guess.
But this isn't a new problem at all, and it turns out that in some cases a CMD/BAT file has VBScript beat hollow!
NET FILE gives back a list of open files and a final "The command completed successfully." line. At the head of each response line is the file ID number. So at a comand prompt you can just type:
Code:
for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close
This works great, except you get an error on the "The" at the head of the final line of response from NET FILE. Just ignore the final error!
BTW, from a CMD/BAT file, the syntax must be:
Code:
for /f "skip=4 tokens=1" %%a in ('net files') do net files %%a /close
I can't take any credit for this one. Found it after a little digging today at: