Skip to content

Instantly share code, notes, and snippets.

@rwv
Created May 22, 2019 06:35
Show Gist options
  • Save rwv/0ecdeba9e2abc51878f297dd834c2836 to your computer and use it in GitHub Desktop.
Save rwv/0ecdeba9e2abc51878f297dd834c2836 to your computer and use it in GitHub Desktop.
Mount UNC path to an available drive and get drive letter
:: mount unc_path to an available drive and get the drive letter
set unc_path=\\ShareHost\ShareFolder
echo unc_path:%unc_path%
net use * %unc_path%
echo mount %unc_path% to available drive
for /f "tokens=2,3" %%i in ('net use') do if '%%j=='%unc_path% set drive_letter=%%i
echo mount to %drive_letter%
%drive_letter%
echo switch to working directory %drive_letter%
net use %drive_letter% /delete /y
echo unmount %drive_letter%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment