test.bat
ansi编码- @echo off & cd /d "%~dp0"
- setlocal enabledelayedexpansion
- for /d %%i in (*) do (
- echo %%i
- for /f "tokens=3" %%a in ('dir /s "%%~i" ^| findstr "个文件"') do set "size=%%a"
- set "size=!size:,=!"
- set "str_size="
- call :_fun "!size!/1024"
- if "!b!"=="0" (
- REM 字节
- set "str_size=!size!B"
- ) else (
- set "k=!b!"
- call :_fun "!b!/1024"
- if "!b!"=="0" (
- REM KB
- set "str_size=!k!KB"
- ) else (
- set "k=!b!"
- call :_fun "!b!/1024"
- if "!b!"=="0" (
- REM MB
- set "str_size=!k!MB"
- ) else (
- REM GB
- set "str_size=!b!GB"
- )
- )
- )
- echo !str_size!
- echo %%i --^> !str_size!-%%i
- rename "%%i" "!str_size!-%%i"
- echo -----------
- )
- pause&exit
- :_calc
- set "_calc=mshta "javascript:var fso=new ActiveXObject("Scripting.FileSystemObject");fso.GetStandardStream(1).WriteLine(%~1);window.close()""
- for /f "delims=" %%i in ('%_calc%') do set "%~2=%%i"
- goto :eof
- :_split
- set "b=%~n1"
- set "c=%~x1"
- set "c=!c:~1!"
- goto :eof
- :_fun
- call :_calc "%~1" "a"
- call :_split "!a!"
- goto :eof
复制代码
|