-4

I'm trying to make a batch script to delete Outlook .ost files bigger than 50GB. But loops with "for" command makes me crazy :( Also try with "forfiles" command but no luky. Any idea?

Hi Dennis! Sorry for so delayed check out...
I have tested it with small ost's and works... but... the IF command don't work with large files... up to ~2GB. I tried with a 45GB file.

Check this:

IF 2147483647 GTR 2147483646 echo A is greater than B (will be TRUE)

IF 2147483648 GTR 2147483647 echo A is greater than B (will be FALSE!)

Just like show on: How can I check the size of a file in a Windows batch script?

I tried transform into GB but not work:

FORFILES /P "%localappdata%\Microsoft\Outlook" /S /M *.ost /C "cmd /c set /a ostsize=@fsize/1073741824 echo @file"

But not work, then found that there is a problem with forfiles command:

FORFILES /P "%localappdata%\Microsoft\Outlook" /S /M *.ost /C "cmd /c echo=@fsize"

Try it with a 45GB file and returns 8052032512 value... :S I'm stuck!

Community
  • 1
  • 1
vyktoor
  • 11
  • 5

3 Answers3

1

if seems not to be able to interprete such big numbers as strings (see related question weird results with IF) as one whould think it should.

And because numbers are limited to 32bit Integer, your only option to work with larger numbers is to explicitely force if to compare them as strings (by enclosing them with qoutes).

In addition, I added a bunch of zeros in front of them and then limited them to a fixed lenght (because with string comparison, 41 is bigger than 296 (4 is bigger than 2), but the string "00041" is smaller than the string "00296" - strings are compared strictly from first to last character)

@echo off
set "size1=2147483647"
set "size2=2147483646"
set "null=000000000000000"
set "size1=%null%%size1%"
set "size2=%null%%size2%"
set "size1=%size1:~-15%"
set "size2=%size2:~-15%"
if "%size1%" gtr "%size2%" echo size1 is greater
Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • IF "2147483648" GTR "2147483647" echo A is greater than B (will be FALSE!) -> now works!!! I don't know about quotes!!! But I can't fix: FORFILES /P "%localappdata%\Microsoft\Outlook" /S /M *.ost /C "cmd /c echo=@fsize" If *.ost size is less than 8052032512 works, but if is bigger still showing 8052032512. Seems that "forfiles" command can't see more thant 8052032512 bytes :S – vyktoor Apr 06 '16 at 13:52
1

Ok, I found the solution: WMIC to rescue!!!!

Do a wmic query and put into a variable:

for /f "tokens=2 delims==" %%f in ('wmic datafile where "path='\\Users\\%username%\\AppData\\Local\\Microsoft\\Outlook\\' and Extension='ost' and FileSize>'48318382080'" get Name /value ^| find "="') do set "file=%%f"
vyktoor
  • 11
  • 5
0

First of all, welcome to stackOverflow. It is custom at this site to provide code you tried yourself for a problem you can't solve, as this is a site for people to help eachother with code, not a free coding service.

Because this particular problem is easy to solve, this is what you need:

@echo off
FORFILES /S /M *.ost /C "cmd /c if @fsize gtr 53687091200 del @file"
Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35
  • Works great! Just wanna start from scratch... I will not do it again, I swear by my mom! – vyktoor Dec 29 '15 at 12:53
  • Except... That doesn't work as the "if" statement can't evaluate numbers over a signed 32bit size. So, your code doesn't work at all for finding files over 50gb in size, the max size you can search for is 2147483646. I found this out via Google and testing my code. – Tim Eckel May 24 '18 at 14:21