ToB企服应用市场:ToB评测及商务社交产业平台
标题:
bat脚本实现摆列当地磁盘,并从A-Z中找出一个可用磁盘映射
[打印本页]
作者:
乌市泽哥
时间:
2024-12-30 15:22
标题:
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%
)
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4