We are having problems when a specific files (.ost) are near to 49GB size and I'm trying to find someway to know before it happens.
I'm looking to list remotely a list and also get the size in GB instead of bytes.
The files will be always inside %userprofile%\AppData\Local\Microsoft\Outlook but sometimes cuould be also a renamed folder like %userprofile%\AppData\Local\Microsoft\Outlook_OLD
With command forfiles somehow :'D I get to show the files:
>c:\>forfiles /P %userprofile%\AppData\Local\Microsoft\ /M *.ost /S /C "cmd /c echo @path >@fsize"
Suited to me but copied from the post https://superuser.com/questions/64481/is-there-a-windows-command-line-utility-to-list-largest-files-exceeding-specific
But, I'm looking for a clean output as this code works:
@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
From this post: How to list all folder with size via batch file
So the idea is to input something like:
"ip address" batchfile.cmd
And output something like
fileName1.ost size 10GB
fileName2.ost size 20GB
fileName3.ost size 20GB
fileName4.ost size 20GB