如题:假如本地计算机有A(软盘)、B(软盘)、C(物理硬盘)、D(光驱,未放光盘),四个盘,则能找出 A:E:、B:F:、C:G:、D:H:四种映射方法,依此类推。
代码通过bat脚本实现
@Echo Off
setlocal enabledelayedexpansionSET 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 %%becho %%b >> %RCOPY_LOG%set /A count+=1set volumeInfo[!count!]=%%b:)
)set /A count=0for /f "tokens=1,2 delims=" %%s in (%SRC_TXT%) do (echo %%s >>%RCOPY_LOG%set /A count+=1set volumeList[!count!]=%%s
)for /l %%i in (1,1,!count!) do (echo !volumeList[%%i]!!volumeInfo[%%i]!>>%RCOPY_XP_PATH%
)