bat脚本实现枚举本地磁盘,并从A-Z中找出一个可用磁盘映射
如题:假如本地计算机有A(软盘)、B(软盘)、C(物理硬盘)、D(光驱,未放光盘),四个盘,则能找出 A:E:、B:F:、C:G:、D:H:四种映射方法,依此类推。
代码通过bat脚本实现
@Echo Off
setlocal enabledelayedexpansion
SET TEMP_DIR=temp.clone
SET RCOPY_LOG=C:\%TEMP_DIR%\rcopy.log
SET RCOPY_XP_PATH=C:\%TEMP_DIR%\diskXP.txt
SET SRC_TXT=C:\%TEMP_DIR%\disk.txt
::disk.txt had writed A:\r\nB:\r\nC:\r\nD:
set /A count=0
set volumeInfo[%count%]="0"
set volumeList[%count%]="0"
:: List of all possible drive letters
set "letters=C D E F G H I J K L M N O P Q R S T U V W X Y Z"
:: Initialize the usedDrives variable
set "usedDrives="
:: Get all current drives and skip the header
for /f "skip=1 tokens=1" %%a in ('wmic logicaldisk get caption') do (
set "usedDrives=!usedDrives! %%~a"
)
:: Check each letter and echo if it's not in use
for %%b in (%letters%) do (
set "found=0"
for %%c in (!usedDrives!) do (
if /i "%%b:"=="%%c" set "found=1"
)
if !found! equ 0 (
echo %%b
echo %%b >> %RCOPY_LOG%
set /A count+=1
set volumeInfo[!count!]=%%b:
)
)
set /A count=0
for /f "tokens=1,2 delims=" %%s in (%SRC_TXT%) do (
echo %%s >>%RCOPY_LOG%
set /A count+=1
set volumeList[!count!]=%%s
)
for /l %%i in (1,1,!count!) do (
echo !volumeList[%%i]!!volumeInfo[%%i]!>>%RCOPY_XP_PATH%
)
原文地址:https://blog.csdn.net/qq_33335872/article/details/144742442
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!