返回列表 发帖
本帖最后由 newswan 于 2021-8-8 09:59 编辑

回复 17# 5i365
        for /f "tokens=2,3 delims= " %%a in ('echo list vol^|diskpart^|findstr /i "volume.*no"') do (
                        (echo select volume %%a
                        echo delete volume)|diskpartCOPY
使用的卷号,而不是盘符
删除一个卷,如果是前面的,后面的卷,卷号自动上移,第一个删除后,下面的全乱了
所以会删错,删不完
把 %%a 改成 %%b

TOP

回复 22# 5i365


你现在用的方法1还是方法2?

TOP

本帖最后由 newswan 于 2021-8-8 12:48 编辑

回复 22# 5i365

改的这一段,%%a 是 卷number %%b 是卷letter,
当然,要有letter 才是正确的,否则就要出错。
@echo off
chcp 437
echo list vol|diskpart|findstr /i "volume.*no" &&set f=1
if not defined f start mshta vbscript:msgbox("not find no",0,"tip")(window.close)&&exit
        for /f "tokens=2,3 delims= " %%a in ('echo list vol^|diskpart^|findstr /i "volume.*no"') do (
                        (echo select volume %%b
                        echo delete volume)|diskpart
                )
        )
pauseCOPY

TOP

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     C                NTFS   Partition    120 GB  Healthy    Boot
  Volume 1     D                NTFS   Partition    356 GB  Healthy
  Volume 2                      FAT32  Partition    260 MB  Healthy    System
  Volume 3     F                NTFS   Partition   1024 MB  Healthy
  Volume 4         New Volume   ReFS   Partition   7165 MB  Healthy
  Volume 5     E       New Vol  NTFS   Partition      9 GB  HealthyCOPY
上面 volume 4 获取盘符就会出错

TOP

本帖最后由 newswan 于 2021-8-8 18:41 编辑

定位硬盘不行,分区号也会自动变
卷号,按大到小排序
cmd /c "echo list vol" ^| diskpart ^| findstr /i /r /C:"Volume [0-9]" ^| sort /r COPY
剩下的你自己改

测试
DISKPART>
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     C                NTFS   Partition    100 GB  Healthy    Boot
  Volume 1     D                NTFS   Partition    138 GB  Healthy
  Volume 2                      FAT32  Partition    260 MB  Healthy    System
  Volume 3                      RAW    Partition    260 MB  Healthy    Hidden
  Volume 4                      RAW    Partition   1023 MB  Healthy
  Volume 5                      RAW    Partition   4096 MB  Healthy
DISKPART> 5
4
3
2
1
0COPY

TOP

总之就是 卷号倒序, 盘符,两个方法
或者没有盘符先分配盘符

TOP

返回列表