标题: [系统相关] [分享]批处理修正盘符 [打印本页]
作者: hfg1977 时间: 2011-5-7 15:16 标题: [分享]批处理修正盘符
在安装数个硬盘的情况下有时会产生盘符交叉问题, 特写此P
注:盘符 卷标 与 卷 是不同的感念,不要混淆.- @echo off
- setlocal enabledelayedexpansion
- if "%~1"=="" (
- call copy "%~0" "%windir%.\..\"
- start "" "%windir%.\..\%~nx0" %~dp0
- exit /b
- )
- set "oldPath=%*"
- echo 工作路径1:%oldPath%
- echo 工作路径:%~dp0
- echo.======== Ver:1.0 ==================== 发布日期: 2010-09-07 ==============
- echo. · 1. 自动
- echo. · 2. 根据Volume.txt的顺序修改盘符
- echo.====================== Copyright@ by hf-g 2010-09-07 [彭城] =============
- set "choice="&set/p choice=输入你的选择(1/2/q):
- if /i "%choice%"=="q" goto end
- echo %choice%|findstr "^[12]$">nul 2>nul&&goto choice%choice%
- goto end
- ::==============================================================
- :choice1
- ::备份及查找各硬盘分区卷的装入点
- cd.>Volume_old.txt
- for /f "delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do (
- set var=%%i
- set drive=!var:~-2!
- fsutil fsinfo drivetype !drive!|find "固定">nul && (for /f "delims= " %%a in ('mountvol !drive! /l') do set "%%a=1" & echo !drive! %%a>>Volume_old.txt)
-
- )
-
- ::根据不同硬盘的枚举顺序修改盘符,跳过C:盘
- if not exist Volume.txt (mountvol|findstr "\\\\\?\\Volume">Volume.txt)
- set "char=DEFGHIJKLMNOPQRSTUVWXYZ"
- @echo on
- set/a count=0
- for /f "skip=1 usebackq delims= " %%a in ("Volume.txt") do (
- call echo !%%a! ++ +%%char:~!count!,1%%+
- if "!%%a!"=="1" (call mountvol %%char:~!count!,1%%: /d & call mountvol %%char:~!count!,1%%: %%a & set/a count+=1)
- )
- @echo off
- goto:eof
- ::==============================================================
- :choice2
- ::根据Volume.txt的顺序修改盘符,跳过C:盘
- if not exist Volume.txt (mountvol|findstr "\\\\\?\\Volume">Volume.txt)
- ::生成Volume_320.txt文件,并删除盘符(跳过C:盘).
- cd.>Volume_320.txt
- for /f %%a in ('mountvol^|findstr "\\\\\?\\Volume :\\"') do (
- set "Volume=%%a"
- if "!Volume:~-2!"==":\" (
- if /i not "%%a"=="%SystemDrive%\" mountvol !Volume:~0,2! /d
- call set "Volume_!count!=!Volume:~0,2! %%Volume_!count!%%"
- ) else (
- set/a num+=1
- set "count=00!num!"
- set "count=!count:~-3!"
- set "Volume_!count!= %%a"
- ))
- set Volume_
- for /f "tokens=2 delims==" %%a in ('set Volume_') do echo %%a>>Volume_320.txt
-
- @echo on
- set /p "Volfile=输入已设定好的Volume文件:"
- if not defined Volfile (set "Volfile=Volume_320.txt")
- copy "%oldPath%.\%Volfile%" "%windir%.\..\"
- for /f "tokens=1,2 usebackq delims= " %%a in ("%Volfile%") do (
- if /i not "%%a"=="%SystemDrive%" (
- call echo +%%a+ ++ +%%b+
- call mountvol %%a %%b
- ))
- @echo off
- ::==============================================================
- pause
- pause
- :end
- goto:eof
- ::==============================================================
复制代码
作者: hfg1977 时间: 2011-5-7 15:21
卷的信息,每次做系统(安装或GHOST),都是不同的,哪怕是同个gho文件且硬件未有任何变动的情况下.
所以备份卷的信息没有任何意义.
作者: yjstone 时间: 2011-5-8 16:22
for /f "delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do .......这句代码在win7下不能正常工作,命令
fsutil fsinfo drives|find /v "" 在win7是这样显示的,跟XP和2003的不一样:
作者: Batcher 时间: 2011-5-8 16:40
Vista跟Win7比较象:
C:\Test>fsutil fsinfo drives|find /v ""
Drives: C:\ D:\ S:\
|
作者: hfg1977 时间: 2011-5-8 18:03
哦, Vista跟Win7是单行显示的呀!
修改以下可以了:- call:isWindowsVer
- for /f "delims=\" %%i in ('if "%isXPlevel%"^=^="1" ^(fsutil fsinfo drives^|find /v ""^) else ^(for /f %%m in ^('fsutil fsinfo drives^^^|find /v ""'^) do echo %%m^)') do (
复制代码
- ::================= 判断Windows版本 ============================
- ::返回值: isXPlevel=1 XP级别;isXPlevel=2 高于XP级别;isXPlevel=0 低于XP级别
- :isWindowsVer
- ver|findstr "5\.[0-9]\.[0-9][0-9]*">nul&&(set isXPlevel=1&goto:eof)
- ver|findstr "6\.[0-9]\.[0-9][0-9]*">nul&&(set isXPlevel=2&goto:eof)
- set isXPlevel=0
- goto:eof
复制代码
作者: CrLf 时间: 2011-5-8 18:08
wmic和fsutil在不同系统的表现不同,前阵子忽然醒悟获取盘符其实还可以用mountvol- for /f %%a in ('mountvol^|find ":\"') do echo %%a
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |