0

我正在研究另一个批处理脚本来检测活动的驱动器号。首先是一个理论上的问题,这是否也会检测或尝试安装/连接到 CD 驱动器?如果是这样,那么我该如何让它只选择驱动器/分区(不包括 USB),然后我将如何让它选择多个分区。

第二个问题是它总是选择最后一个字母作为驱动器,例如,这将选择驱动器“Z”。如果我删除字母 Z 那么它将选择驱动器 Y 等等。

@echo off 
:main
cls
set "LW=" 
FOR %%I in (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET "LW=%%I" 
if defined LW ( 
echo *************************** 
echo * External drive is: %LW% * 
echo *************************** 
) ELSE ( 
echo ************************** 
echo * no external disk found * 
echo ************************** 
) 
echo.
echo Task
echo *************************** 
echo 1: Transfer from Partition 2 to Partition 1
echo 2: Transfer from Backup Folder to Partition 2
echo 3: Exit
echo *************************** 
echo.
set /p task=Pick Task: 

if %task%==1 (
    mkdir "%Userprofile%\Desktop\Second Partition"
    xcopy "%LW%:\*" "%Userprofile%\Desktop\Second Partition" /s /i /y /e
    echo Operation completed successfully
    pause
    goto eof
)
if %task%==2 (
    xcopy "%Userprofile%\Desktop\Second Partition\*" %LW%:\ /s /i /y /e
    echo Operation completed successfully
    pause
    goto eof
)
if %task%==3 (
    exit
)
if not "%task%"=="" (
echo Invalid Selection 
pause 
cls
goto main 
)
:eof
exit
4

1 回答 1

0

试一试 - 如果它有效,则解析出“固定磁盘”

@echo off
for /f "tokens=1,*" %%a in ('fsutil fsinfo drives ^| find ":" ') do (
for %%c in (%%b) do fsutil fsinfo drivetype %%c
)
pause
于 2013-08-29T00:05:08.490 回答