Solved Batch filesize compare code?

October 2, 2014 at 16:04:28
Specs: Windows 7
Hi,

I'm trying to check filesize and if GTR than 400 do one thing ESLE do another. I keep getting an error msg. saying 'file not found'. Assume its error in my code. Here is the code:

FOR /F "tokens=4 delims= " %%i in ('dir /-C %od-user% ^| find /I "Scrout"') do (  
    IF /I %%i GTR 400 (
	copy scrout  %f-out% > nul
	copy scrout+output %od-tools%\FC-Compiler\~out.txt > nul
    ) ELSE (
	set f-out=%FCname%.txt
	copy scrout+output %f-out% > nul
	copy scrout+output %od-tools%\FC-Compiler\~out.txt > nul  
    )
)
dir scrout
@echo off
 %WINDIR%\notepad.exe %f-out%

Here is most of the responses from a run:

 ooo
'Run-ALL' execution complete
  -------------------

Next will list tabular results, if any found.

=== turned ECHO ON ===
Waiting for 3 seconds, press a key to continue ...

E:\Tools.vb\FC-Compiler\testing>FOR /F "tokens=4 delims= " %i in ('dir /-C testing | find /I "Scrout"') do (IF /I %i GTR 400 (
 copy scrout  fitexam.outLst  1>nul  
 copy scrout+output e:\tools.vb\FC-Compiler\~out.txt  1>nul 
)  ELSE (
<i>set f-out=fitexam.txt </i> 
 copy scrout+output fitexam.outLst  1>nul  
 copy scrout+output e:\tools.vb\FC-Compiler\~out.txt    1>nul 
) ) 
=== This states here that 'File NOT found' ... twice ===

=== NotePad %f-out% cmd. ... NotePad says 'fitExam.outLst file not found'.  This means the test failed ... %f-out% does NOT = 'fitexam.txt' ... 1st cmd under 'ELSE' above.

E:\Tools.vb\FC-Compiler\testing>dir scrout 
 Volume in drive E is Textbook
 Volume Serial Number is 1E41-B870

 Directory of E:\Tools.vb\FC-Compiler\testing

10/02/2014  03:26 PM               209 Scrout
               1 File(s)            209 bytes
               0 Dir(s)  73,284,943,872 bytes free
 Volume in drive E is Textbook
 Volume Serial Number is 1E41-B870

 Directory of E:\Tools.vb\FC-Compiler\testing

I get the idea that ... ('dir /-C testing | find /I "Scrout"') ... code is not finding my 'Scrout' file in my 'testing' directory, whats wrong with code?

Phil


See More: Batch filesize compare code?

Report •


#1
October 2, 2014 at 19:40:39
1) Several vars have not been assigned values: od-user, f-out, od-tools, and FC-name
unless they were assigned elsewhere in code that was not presented. Echo their values if in doubt.
2) The logic of the DIR structure makes an assumption that should not be assumed, that "scrout" is simply "scrout" and not "scrout.a" or "scrout.b" or "zscrout.txt" etc etc. I am curious as to why you used the method of "dir .. find" instead of plain old "dir scrout" plus whatever. What exactly are you trying to find, as regards filename? *scrout*.*, scrout.*, scrout., *scrout*. or scrout*.*? Your test assumes "scrout." but your FOR/DIR/FIND construct includes all the above wildcard combinations.

You could achieve the same with:

:: I don't know what mask you intend, so I just made this as placeholder
set mask=scrout*.*
for /r %%a in (%mask%) do (
  if %%~za gtr 400 (
  :: do stuff here
  ) else (
  :: do other stuff here
  )
)

message edited by nbrane


Report •

#2
October 3, 2014 at 14:26:52
"2) The logic of the DIR structure makes an assumption that should not be assumed, that "scrout" is simply "scrout" and not "scrout.a" or "scrout.b" or "zscrout.txt" etc etc. I am curious as to why you used the method of "dir .. find" instead of plain old "dir scrout" plus whatever. What exactly are you trying to find, as regards filename? *scrout*.*, scrout.*, scrout., *scrout*. or scrout*.*? Your test assumes "scrout." but your FOR/DIR/FIND construct includes all the above wildcard combinations."

Yes, "scrout" is what I'm searching for ... no '.' nor anything else ... just "scrout". I tried your script and it worked!!!

Thanks for the help. :)
Phil

message edited by OptimalDesigns


Report •

#3
October 3, 2014 at 17:58:34
✔ Best Answer
hmm. You might get unintended results, then, unless you change the mask to:
set mask=scrout
What I presented will include any filename that begins with "scrout", which could get files you don't want. Just thought I'd warn you in advance. Good luck :)

Report •

Related Solutions

#4
October 4, 2014 at 09:19:45
Thanks for the info.

Report •


Ask Question