С помощью этого скрипта меняю буквы на CD-DVD. Адаптируйте под себя и пользуйтесь.
Код:
@cmdow @ /HID
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
Rem Tip obrabatyvaemyh privodov i vydelennye dlia nih bukvy
SET DRV_TYPE=DVD CD
SET DRV_FREE=Q Z Y
Echo.
Echo.Progress: Proveriaem nalichie DiskPart...
DiskPart.Exe /? >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
Echo.
Echo.Progress: Fajl DISKPART.EXE ne najden, rabota skripta prervana!
PAUSE
EXIT
)
Echo.Progress: Opredeliaem lokalizaciju DiskPart...
DiskPart.Exe /?|Find "On computer:"
IF %ERRORLEVEL%==0 (
SET POS_VOL=7
SET POS_LTR=13
SET POS_TYP=37
) ELSE (
SET POS_VOL=4
SET POS_LTR=10
SET POS_TYP=34
)
echo.Progress: Vychisliaem kolichestvo propuskaemyh strok...
SET SKIP=0
FOR /F "tokens=1 delims=[]" %%A IN ('@echo list volume^|@diskpart^|find /N "DISKPART>"') Do IF !SKIP! EQU 0 SET /A SKIP=%%A+2
Echo.Progress: Formiruem spisok ustrojstv, fil'truem perenaznachennye ranee...
FOR /F "skip=%SKIP% tokens=*" %%A IN ('@echo list volume^|@diskpart') Do (
SET LINE=%%A
SET DRV_USED=!DRV_USED! !LINE:~%POS_LTR%,1!
CALL :FIND !LINE:~%POS_LTR%,1! "%DRV_FREE%"
IF !ERRORLEVEL!==1 FOR %%B IN (%DRV_TYPE%) DO CALL :TEST_DRIVE %%B
)
IF "%VOL_WORK%"=="" (
echo.
echo.Progress: Spisok perenaznachenija pust^^^! Skript zavershil rabotu.
EXIT
)
Echo.Progress: Vypolniaem perenaznachenie po sformirovannomu spisku...
Echo.
FOR %%A IN (%VOL_WORK%) DO (
CALL :FindNext
CALL :ASSIGN %%A !LTR!
SET DRV_USED=!DRV_USED! !LTR!
)
EXIT
Rem Obrabotka ocherednoj stroki komandy DiskPart "list volume"
:TEST_DRIVE
CALL :LENGTH %~1
IF "%~1"=="!LINE:~%POS_TYP%,%LENGTH%!" SET VOL_WORK=!VOL_WORK! !LINE:~%POS_VOL%,1!
GOTO :EOF
Rem Vychislenie dliny parametra
:LENGTH
SET LENBUF=%~1
SET LENGTH=0
IF "%~1"=="" GOTO :EOF
:LENGTH_START
SET /A LENGTH+=1
IF ""=="!LENBUF:~%LENGTH%,1!" GOTO :EOF
GOTO :LENGTH_START
Rem Vyzov komandy naznachenija
:ASSIGN
(@echo select volume %~1&@echo assign letter=%~2)|diskpart|find /I "DiskPart:"
GOTO :EOF
Rem Vyzov komandy FIND
:FIND
@echo %~2|@find "%~1">nul
GOTO :EOF
Rem Poisk svobodnoj bukvy iz zadannogo mnozestva
:FindNext
For %%i in (%DRV_FREE%) Do (
@echo.%DRV_USED%|Find "%%i">nul
IF !ERRORLEVEL!==1 (
SET LTR=%%i
GOTO :EOF
)
)
Echo.
Echo.Skript prervan^! Spisok svobodnyh bukv ischerpan.
EXIT