标题: [数值计算] 【已解决】BAT脚本kytes转换mb计算时超过32精确度 [打印本页]
作者: 赖渊 时间: 2021-5-9 13:57 标题: 【已解决】BAT脚本kytes转换mb计算时超过32精确度
本帖最后由 赖渊 于 2021-5-11 06:41 编辑
我使用了普通的bat除法命令,然而会出现数值过大导致无法计算。
请问有大佬给个好点子吗?
http://www.bathome.net/viewthread.php?tid=3372
计算函数部分用的是这个,但是感觉除法这个帖子的函数太复杂了....- PUSHD %~DP0 &TITLE 删除sewwo教学程序日志淤积(赖渊)
- @echo off&chcp 437>nul&setlocal enabledelayedexpansion
-
- for /f "delims=" %%l in ('dir "D:\" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 1=%%a)
- )
- echo !1! bytes %统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir F:\%1 /a-d /b /s') do @set /a num1+=1 %统计数目%
- ::第一次计算用户目录sewwo日志目录文件个数及大小
-
- for /f "delims=" %%l in ('dir "D:\" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 2=%%a)
- )
- echo !2! bytes%统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir F:\%1 /a-d /b /s') do @set /a num2+=1 %统计数目%
- ::第一次计算系统目录sewwo日志目录文件个数及大小
-
- call :jia !1! !2! dx1
- echo %dx1% bytse
-
- call :jia %num1% %num2% sm1
- echo %sm1%
-
- ::第一次调用加法函数统计删除前日志目录总文件数及大小
-
- for /f "delims=" %%l in ('dir "D:\" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 3=%%a)
- )
- echo !3! bytes %统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir F:\%1 /a-d /b /s') do @set /a num3+=1 %统计数目%
- ::第二次计算用户目录sewwo日志目录文件个数及大小
-
- for /f "delims=" %%l in ('dir "D:\" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 4=%%a)
- )
- echo !4! bytes %统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir F:\%1 /a-d /b /s') do @set /a num4+=1 %统计数目%
- ::第二次计算系统目录sewwo日志目录文件个数及大小
-
- call :jia !3! !4! dx2
- echo %dx2% bytse
-
- call :jia %num3% %num4% sm2
- echo %sm2%
-
- ::第二次调用加法函数统计删除后日志目录文件数及总大小
-
- call :jian %dx1% %dx2% dx3
- echo %dx3% bytse
- ::计算前后空间减少的大小
-
- call :jian %sm1% %sm2% sm3
- echo %sm3%
- ::计算前后文件减少的数目
-
- set /a a=%dx1%,b=1048576
- set /a result=%a%/%b%
- echo %a%/%b%=%q%
- set /a a=%dx2%,b=1048576
- set /a result=%a%/%b%
- echo %a%/%b%=%h%
- set /a a=%dx3%,b=1048576
- set /a result=%a%/%b%
- echo %a%/%b%=%t%
- ::bytes转换成MB
-
- @echo off&CHCP 936>nul
-
- echo 清理前%q%MB,清理后%h%MB,共清理了%t%MB,总共%sm3%个文件
- echo laiyuanys.ys168.com
-
- pause > nul
-
-
- :jia 加法计算函数
- setlocal enabledelayedexpansion&set f=&set "t="
- set var1=%~1&set var2=%~2&set /a j=0,n1=0,n2=0
- for /l %%a in (0 1 9) do (set vard1=&set "vard2="
- set var1=!var1:%%a= %%a !&set var2=!var2:%%a= %%a !)
- for %%a in (!var1!)do (set/a n1+=1&set vard1=%%a !vard1!)
- for %%a in (!var2!)do (set/a n2+=1&set vard2=%%a !vard2!)
- (if !n1! lss !n2! (set var1=%var2%&set "var2=%var1%"
- set vard1=%vard2%&set vard2=%vard1%))&set "var2=!var2: =!"
- for %%a in (!vard1!) do (if "!var2!"=="" set /a var2=0
- set /a a=%%a+!var2:~-1!+j&set t=!a:~-1!!t!&set "a=0!a!"
- set "j=!a:~-2,1!"&set var2=!var2:~0,-1!)
- if !j! neq 0 set "t=!j!!t!"
- Endlocal&set %~3=%t%&goto :EOF
-
- :jian 减法计算函数
- setlocal enabledelayedexpansion&&set t=&set f=&set "lin="
- for /l %%a in (1 1 10) do set "lin=0000000000!lin!"
- set lin=!lin!!lin!!lin!!lin!!lin!&set "lin=!lin!!lin!"
- set var1=!lin!%~1&set var2=!lin!%~2&set vard1=&set/a j=0
- set var1=!var1:~-1000!&set "var2=!var2:~-1000!"
- if "!var1!" lss "!var2!" (set var1=%~2&set "var2=%~1"
- set "f=-") else set var1=%~1&set "var2=%~2"
- for /l %%a in (0 1 9) do set "var1=!var1:%%a= %%a !"
- for %%a in (!var1!) do set "vard1=%%a !vard1!"
- for %%a in (!vard1!) do (if "!var2!"=="" set/a var2=0
- set /a a=%%a-j,b=!var2:~-1!
- if !a! lss !b! (set /a a+=10,j=1)else set /a j=0
- set /a w=a-b&set t=!w!!t!&set var2=!var2:~0,-1!)
- for /f "tokens=* delims=0" %%a in ("!t!") do (
- if "%%a"=="" (set t=0) else set "t=%%a")
- Endlocal&set %~3=%f%%t%&goto :EOF
复制代码
bat脚本打算是用来删除班上电脑sewwo教学系列程序的日志淤积文件用的(大概2G左右)
路径还没有写入,这个无视就好。。。。
麻烦各位了。。。
作者: went 时间: 2021-5-9 15:32
http://www.bathome.net/viewthrea ... hlight=%B4%F3%CA%FD
3楼
作者: newswan 时间: 2021-5-9 19:56
用powershell 计算- powershell -c " 10000000000000 /1024 /1024 /1024 /1024 "
复制代码
作者: 赖渊 时间: 2021-5-10 06:28
回复 3# newswan
谢谢Thanks♪(・ω・)ノ,似乎能计算起来了,但是输出结果不知道怎么调用起来。。。。
作者: Batcher 时间: 2021-5-10 07:57
回复 4# 赖渊 - @echo off
- for /f %%i in ('powershell -c "10000000000000 /1024 /1024 /1024 /1024"') do (
- set "n=%%i"
- )
- echo %n%
- pause
复制代码
作者: 赖渊 时间: 2021-5-10 11:13
回复 5# Batcher - PUSHD %~DP0 &TITLE 清理sewwo教学程序日志淤积(赖渊)
- @echo off&chcp 437>nul&setlocal enabledelayedexpansion
- color 0a
-
- for /f "delims=" %%l in ('dir "%userprofile%\AppData\Roaming\Seewo" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 1=%%a)
- )
- echo !1! bytes %统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir %userprofile%\AppData\Roaming\Seewo%1 /a-d /b /s') do @set /a num1+=1 %统计数目%
- ::第一次计算用户目录sewwo日志目录文件个数及大小
-
- for /f "delims=" %%l in ('dir "%systemdrive%\ProgramData\Seewo" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 2=%%a)
- )
- echo !2! bytes%统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir %systemdrive%\ProgramData\Seewo%1 /a-d /b /s') do @set /a num2+=1 %统计数目%
- ::第一次计算系统目录sewwo日志目录文件个数及大小
-
- call :jia !1! !2! dx1
- echo %dx1% bytse
-
- call :jia %num1% %num2% sm1
- echo %sm1%
-
- ::第一次调用加法函数统计删除前日志目录总文件数及大小
-
- @ echo on
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\EasiAssistant"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\EasiCamera\Log"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\EasiNote3C\Log"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\EasiNote5\Log"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\EasiRecorder\logs"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\ECGuardian\Log"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\SeewoAdClose"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\SeewoLink\logs"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\SeewoLinkService\logs"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\SeewoService"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\SeewoService5"
-
- del /s /q "%userprofile%\Desktop\Seewo\logs
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\SeewoServiceUpdater"
-
- del /s /q "%userprofile%\AppData\Roaming\Seewo\UpgraderTo41"
-
- del /s /q "%systemdrive%\ProgramData\Seewo\SeewoAdminService"
-
- del /s /q "%userprofile%\Desktop\Seewo\SeewoAdminService"
-
- del /s /q "%userprofile%\Desktop\Seewo\Easiupdate\easiupdate\logs"
-
- del /s /q "%userprofile%\Desktop\Seewo\SeewoGuard"
-
- del /s /q "%userprofile%\Desktop\Seewo\Easiupdate3Logs"
-
- del /s /q "%systemdrive%\ProgramData\Seewo\SeewoGuard"
-
- del /s /q "%systemdrive%\ProgramData\Seewo\Easiupdate3Logs"
-
- del /s /q "%systemdrive%\ProgramData\Seewo\logs"
-
- del /s /q "%systemdrive%\ProgramData\Seewo\LiveProxyGuard"
-
- del /s /q "%systemdrive%\ProgramData\Seewo\Easiupdate\easiupdate\logs"
-
- ::清理sewwo教学程序淤积日志文件
-
- ping 127.0.0.1 -n 2 >nul
-
- color 0C
-
- net stop wuauserv
-
- del /s /q "%systemdrive%\Windows\SoftwareDistribution\DataStore
-
- color 0a
-
- ping 127.0.0.1 -n 2 >nul
-
- net start wuauserv
-
- @ echo off
-
- for /f "delims=" %%l in ('dir "%userprofile%\AppData\Roaming\Seewo" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 3=%%a)
- )
- echo !3! bytes %统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir F:\%1 /a-d /b /s') do @set /a num3+=1 %统计数目%
- ::第二次计算用户目录sewwo日志目录文件个数及大小
-
- for /f "delims=" %%l in ('dir "D:\" /a /s /-c ^| findstr /i "bytes$"') do (
- for /f "tokens=3 delims= " %%a in ("%%l") do (set 4=%%a)
- )
- echo !4! bytes %统计大小%
-
- set num=0
- for /f "delims=" %%i in ('dir %systemdrive%\ProgramData\Seewo%1 /a-d /b /s') do @set /a num4+=1 %统计数目%
- ::第二次计算系统目录sewwo日志目录文件个数及大小
-
- call :jia !3! !4! dx2
- echo %dx2% bytse
-
- call :jia %num3% %num4% sm2
- echo %sm2%
-
- ::第二次调用加法函数统计删除后日志目录文件数及总大小
-
- call :jian %dx1% %dx2% dx3
- echo %dx3% bytse
- ::计算前后空间减少的大小
-
- call :jian %sm1% %sm2% sm3
- echo %sm3%
- ::计算前后文件减少的数目
-
- for /f %%i in ('powershell -c "%dx1% /1024 /1024"') do (
- set "q=%%i"
- echo %q%
-
- set /a a=%dx2%,b=1048576
- set /a result=%a%/%b%
- echo %a%/%b%=%h%
- set /a a=%dx3%,b=1048576
- set /a result=%a%/%b%
- echo %a%/%b%=%t%
- ::bytes转换成MB
-
- CHCP 936>nul
- Cls
- @ echo.
- echo 清理前%q%MB,清理后%h%MB,共清理了%t%MB,总共%sm3%个文件
- echo laiyuanys.ys168.com
- pause > nul
-
-
- :jia 加法计算函数
- setlocal enabledelayedexpansion&set f=&set "t="
- set var1=%~1&set var2=%~2&set /a j=0,n1=0,n2=0
- for /l %%a in (0 1 9) do (set vard1=&set "vard2="
- set var1=!var1:%%a= %%a !&set var2=!var2:%%a= %%a !)
- for %%a in (!var1!)do (set/a n1+=1&set vard1=%%a !vard1!)
- for %%a in (!var2!)do (set/a n2+=1&set vard2=%%a !vard2!)
- (if !n1! lss !n2! (set var1=%var2%&set "var2=%var1%"
- set vard1=%vard2%&set vard2=%vard1%))&set "var2=!var2: =!"
- for %%a in (!vard1!) do (if "!var2!"=="" set /a var2=0
- set /a a=%%a+!var2:~-1!+j&set t=!a:~-1!!t!&set "a=0!a!"
- set "j=!a:~-2,1!"&set var2=!var2:~0,-1!)
- if !j! neq 0 set "t=!j!!t!"
- Endlocal&set %~3=%t%&goto :EOF
-
- :jian 减法计算函数
- setlocal enabledelayedexpansion&&set t=&set f=&set "lin="
- for /l %%a in (1 1 10) do set "lin=0000000000!lin!"
- set lin=!lin!!lin!!lin!!lin!!lin!&set "lin=!lin!!lin!"
- set var1=!lin!%~1&set var2=!lin!%~2&set vard1=&set/a j=0
- set var1=!var1:~-1000!&set "var2=!var2:~-1000!"
- if "!var1!" lss "!var2!" (set var1=%~2&set "var2=%~1"
- set "f=-") else set var1=%~1&set "var2=%~2"
- for /l %%a in (0 1 9) do set "var1=!var1:%%a= %%a !"
- for %%a in (!var1!) do set "vard1=%%a !vard1!"
- for %%a in (!vard1!) do (if "!var2!"=="" set/a var2=0
- set /a a=%%a-j,b=!var2:~-1!
- if !a! lss !b! (set /a a+=10,j=1)else set /a j=0
- set /a w=a-b&set t=!w!!t!&set var2=!var2:~0,-1!)
- for /f "tokens=* delims=0" %%a in ("!t!") do (
- if "%%a"=="" (set t=0) else set "t=%%a")
- Endlocal&set %~3=%f%%t%&goto :EOF
复制代码
修改成- for /f %%i in ('powershell -c "%dx1% /1024 /1024"') do (
- set "q=%%i"
- echo %q%
复制代码
就不执行下面的运算函数而是直接退出
我尝试添加复制代码
来看看运行过程也都是直接退出。。。。
作者: Batcher 时间: 2021-5-10 11:50
回复 6# 赖渊 - for /f %%i in ('powershell -c "%dx1% /1024 /1024"') do (
- set "q=%%i"
- )
- echo %q%
复制代码
作者: 赖渊 时间: 2021-5-11 06:40
回复 7# Batcher
非常非常非常感谢!!
谢谢两位大佬,辛苦了
(o゚▽゚)o
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |