0
echo off
SETLOCAL EnableDelayedExpansion
set caminho="C:\Users\%username%\AppData\Local\Microsoft\Outlook"

set maxbytesize=10



for /F %%i in ('dir /b "C:\Users\%username%\AppData\Local\Microsoft\Outlook\*.ost"') do (


   set directoria=%caminho%\%%i

%1 %0 :: %directoria%
set len=%~z2

if %len% LSS %maxbytesize% (
msg * algo
PAUSE

) ELSE (
msg * O ficheiro exedeu 29Gb, diriga-se a Informatica

)

)

Im not so good in this so i need some help. I have a similar code that works, but when i "transform" into this it starts to say that 10 is not expected being 10 the %maxbytesize%. There some way to make this work or i need to start all over again??

  • 2
    Essentially the same as http://stackoverflow.com/questions/42438092/batch-file-to-check-file-with-the-same-extension. The problem is `delayed expansion` - please search SO for many articles about this. The fundamental issue is that `len` is undefined when the `for/f` is reached, so it is replaced by *nothing* which violates the `if` statement syntax. I have no idea what `%1 %0 :: %directoria%` is supposed to achieve since you haven't provided the parameters you are using. – Magoo Mar 01 '17 at 15:07
  • [This question](http://webcache.googleusercontent.com/search?q=cache:aW-mXC4F_lkJ:stackoverflow.com/questions/42420902/way-of-batch-file-check-various-file-with-the-same-extention+&cd=3&ct=clnk) appears to have been asked previously, _and now no longer available_ here. – Compo Mar 01 '17 at 17:26

1 Answers1

0

None of those variables need setting because they are not used outside of the code or manipulated within the code:

@Echo Off
Rem If "%~1"=="" Exit/B

Set "MaxByteSize=31138512896"

For %%A In ("%LocalAppData%\Microsoft\Outlook\*.ost") Do (
    Rem "%~1" "%~f0" :: "%%~fA"
    If %%~zA Lss %MaxByteSize% (msg * algo) Else (
        msg * O ficheiro exedeu 29Gb, diriga-se a Informatica))

If you really are running the script with a single argument then remove both instances of Rem.

Compo
  • 36,585
  • 5
  • 27
  • 39