如何通过批处理文件列出大小的特定文件?

时间:2014-06-05 16:07:20

标签: windows file batch-file size

当特定文件(.ost)接近49GB大小时我们遇到问题,并且我试图在它发生之前找到它。

我希望远程列出一个列表,并以GB为单位而不是字节。

文件将始终位于%userprofile%\ AppData \ Local \ Microsoft \ Outlook内,但有时也可能是重命名的文件夹,如%userprofile%\ AppData \ Local \ Microsoft \ Outlook_OLD

以某种方式使用命令forfiles:'我可以显示文件:

>c:\>forfiles /P %userprofile%\AppData\Local\Microsoft\ /M *.ost /S /C "cmd /c echo @path >@fsize"

适合我,但是从帖子https://superuser.com/questions/64481/is-there-a-windows-command-line-utility-to-list-largest-files-exceeding-specific

复制

但是,我正在寻找一个干净的输出,因为这段代码可以工作:

@echo off
setlocal disabledelayedexpansion

set "folder=%~1"
  if not defined folder set "folder=%cd%"

    for /d %%a in ("%folder%\*") do (
        set "size=0"
        for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:"  "') do if "%%~c"=="" set "size=%%~b"
        setlocal enabledelayedexpansion
        call :GetUnit !size! unit
        call :ConvertBytes !size! !unit! newsize
        echo(%%~nxa - !newsize! !unit!
        endlocal
    )

endlocal

exit /b

:ConvertBytes bytes unit ret
setlocal
if "%~2" EQU "KB" set val=/1024
if "%~2" EQU "MB" set val=/1024/1024
if "%~2" EQU "GB" set val=/1024/1024/1024
if "%~2" EQU "TB" set val=/1024/1024/1024/1024
> %temp%\tmp.vbs echo wsh.echo FormatNumber(eval(%~1%val%),1)
for /f "delims=" %%a in ( 
  'cscript //nologo %temp%\tmp.vbs' 
) do endlocal & set %~3=%%a
del %temp%\tmp.vbs
exit /b


:GetUnit bytes return
set byt=00000000000%1X
set TB=000000000001099511627776X
if %1 LEQ 1024 set "unit=Bytes"
if %1 GTR 1024   set "unit=KB"
if %1 GTR 1048576  set "unit=MB"
if %1 GTR 1073741824  set "unit=GB"
if %byt:~-14% GTR %TB:~-14% set "unit=TB"
endlocal & set %~2=%unit%
exit /b

从这篇文章: How to list all folder with size via batch file

所以我的想法是输入类似的内容:

"ip address" batchfile.cmd 

输出类似

的内容
fileName1.ost size 10GB
fileName2.ost size 20GB
fileName3.ost size 20GB
fileName4.ost size 20GB

0 个答案:

没有答案