7 replies
by ndambrosio
by roman_empire
by bryan
Here's your batchfile:
--begin here --
if "%1"=="" (echo You must specify a filename and path as the argument to this command) & goto eof
if not "%2"=="" echo Too many arguments
net file > junk.tmp
for /f "skip=4 tokens=1,2 delims= " %%a in(junk.tmp) do call :parseit %%a %%b %1
del junk.tmp
goto :eof
:parseit
::%1 is %%a from above (the file id)
::%2 is %%b from above (the filename with path as output from the NET FILE command)
::%3 is the specified filename (as provided via commandline argument)
if /I "%2"=="%3" net file %1 /close & echo id %1 (%2) was closed
goto :eof
-- end here --
Please notice that you have to specify the full path to the file (d:\path\file.txt) as the argument.
by bryan
The html sets word wrap too narrow. Here's the same code, and I have put a "|ret|" in each place there should be a carriage return:
--begin here --
if "%1"=="" (echo You must specify a filename and path as the argument to this command) & goto:eof|ret|
if not "%2"=="" (echo Too many arguments) & goto :eof|ret|
net file > junk.tmp|ret|
for /f "skip=4 tokens=1,2 delims= " %%a in (junk.tmp) do call :parseit %%a %%b %1
del junk.tmp|ret|
goto :eof|ret|
|ret|
:parseit|ret|
::%1 is %%afrom above (the file id)|ret|
::%2 is %%b from above (the filename with path as output from the NET FILE command)
::%3 is the specified filename (as provided via commandline argument)|ret|
if /I "%2"=="%3" net file %1 /close & echo id %1 (%2) was closed|ret|
goto :eof|ret|
-- end here --
by bryan
Arrrrgh! These teeny text-edit windows are screwing me up! One last chance for me to get this right:
if "%1"=="" (echo You must specify a filename and path as the argument to this command) & goto :eof|ret|
if not "%2"=="" (echo Too many arguments) & goto :eof|ret|
net file > junk.tmp|ret|
for /f "skip=4 tokens=1,2 delims= " %%a in (junk.tmp) do call :parseit %%a %%b %1|ret|
del junk.tmp|ret|
goto :eof|ret|
|ret|
:parseit|ret|
::%1 is %%a from above (the file id)|ret|
::%2 is%%b from above (the filename with path as output from the NET FILE command)|ret|
::%3 is the specified filename (as provided via commandline argument)|ret|
if /I "%2"=="%3" net file %1 /close & echo id %1 (%2) was closed|ret|
goto :eof|ret|There we go. Now just replace each occurrence of "|ret|" with a carriage return (very important, there can be no spaces after the "goto :eof" statements!!)
-Bryan
by roman_empire
Thank you very much.
Great script.
by roman_empire
This discussion is closed to new replies.
Trending Windows Forum posts
Sort by Trending