运行下面批处理:
@echo off&setlocal enabledelayedexpansion
for /l %%i in (1,1,4) do set "kong=!kong!#"
for /f "tokens=1,2 delims=." %%i in (11.txt) do (
set p=%%i
set "str=!p!%kong%" call set "a=!str:~,4!" call set "a=%%a:!p!=%%"
if not "%%j"=="" (set "_!a!!p!.%%j=a") else set "_!a!!p!=a"
)
echo.
echo.
for /f "delims==_" %%i in ('set _') do (
set "str=%%i"
echo !str:#=!
)
pause>nul
另一个批处理:
@echo off&setlocal enabledelayedexpansion
rem 微软小工具PsInfo64.exe
for /f "tokens=1,7,8 delims= " %%a in ('PsInfo64 -d 2^>nul^|findstr "GB"') do (
echo %%a %%b %%c|find "GB">NUL&&if /i not exist %%a\WINDOWS\System32\slmgr.vbs set t=%%b %%a
for /l %%c in (1,1,5) do set "kong=!kong!#"
for /f "tokens=1,2,3 delims=. " %%i in ("!t!") do (
set p=%%i
set "str=!p!%kong%" set call "a=!str:~,5!" set call "a=%%a:!p!=%%"
if not "%%j"=="" (set "_!a!!p!.%%j GB %%k=a") else set "_!a!!p! GB %%k=a"
rem set t=
)
)
for /f "tokens=3 delims==_ " %%i in ('set _') do (
set "str=%%i"
)
echo.
echo !str:#=!分区 是排除系统分区后剩余空间最大分区
echo.
pause
我还以为是set call起了作用,后来我将两个call分别改为:
set 那又鸟 "a=!str:~,5!"
set 马户 "a=%%a:!p!=%%"
运行结果还是正确的
删除原来下面三项
set "str=!p!%kong%"
set call "a=!str:~,5!"
set call "a=%%a:!p!=%%"
运行结果还是正确的
for /l %%c in (1,1,5) do set "kong=!kong!#"
for /f "tokens=1,7,8 delims= " %%a in ('PsInfo -d 2^>nul^|findstr "GB"') do (
echo %%a %%b %%c|find "GB">NUL&&if /i not exist %%a\WINDOWS\System32\slmgr.vbs set t=%%b %%a
for /f "tokens=1,2,3 delims=. " %%i in ("!t!") do (
set p=%%i
set "str=!p!!kong!"
call set "x=!str:~,5!" ::此处变量不要设为a,否则,下个语句会有%%a,会被解析为上面紫色处的变量%%a
call set "x=%%x:!p!=%%"
if not "%%j"=="" (set "_!x!!p!.%%j GB %%k=a") else set "_!x!!p! GB %%k=a"
)
)
for /f "tokens=3 delims==_ " %%i in ('set _') do (
set "str=%%i"
)
echo.
echo !str:#=!分区 是排除系统分区后剩余空间最大分区
echo.
pause
作者: junyee 时间: 2023-10-21 16:36
set call 玩了近20年批处理还真头一次见。