Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
January 17, 1999
There are times you need to assign a temporary drive letter in a batch file, and delete it when you are done.
Here is fragment of such a script: (Note: %1 in this fragment is a UNC path parameter)
for /f "Tokens=*" %%i in ('net use * %1') do call :what "%%i"if not defined drv goto errorREM Do whatever@echo %drv%net use %drv% /deletegoto end:whatset tst=%1if not "%tst:~8,1%"
Another solution is to use PUSHD and POPD:
for /f "Tokens=*" %%i in ('CD') do set old=%%ipushd %1for /f "Tokens=*" %%i in ('CD') do set drv=%%iif "%old%""%drv%" goto errorREM Do whatever@echo %drv%popd:end
You May Also Like