Sign in to follow this  
Followers 0
meetrix

File Size Query

12 posts in this topic

I need some help. If I have a file that is 5K, how can I set this value. And if the value is less than 5K to error and stop.

This is what I have so far... let me know. Any help would be appreciated.

$size = FileGetSize("c:\customerlogs\0007854963214578.log")
If $size = <> 1-5 Then
    MsgBox (0, "Error", "File size is incorrect!")
Else
    MsgBox (0,"Results", $size)
EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$size = FileGetSize("test.txt")

MsgBox(262144, "", $size)
If $size < 5000 Then
    MsgBox (0, "Error", "File size is incorrect!")
Else
    MsgBox (0,"Results", $size)
EndIf

Edited by Lapo

Share this post


Link to post
Share on other sites

Thanks guys for the help. I did reliaze that the logs sizes varied. I thought that this would be the best way to find out if the log file is good (Passed) or bad (Failed). So, I'm now forced to take a different approach. I will have to read the line or search for the text withing the file. Does anyone have any ideas? This is what I have to far:

Total pass: 24 is the line I need to search. Then provide options what do if found or not found. Some how this script keeps looping???? I have attached the text file.

$file = FileOpen("0173032006000041.txt", 0)
$var = EnvSet("Passed", "Total Pass:15")

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file,15)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)
    If $var Then
    MsgBox(0, "Passed:", "Test Results are Good, Ready to Print")   
    EndIf
Wend

FileClose($file)

$size = FileGetSize("test.txt")

MsgBox(262144, "", $size)
If $size < 5000 Then
    MsgBox (0, "Error", "File size is incorrect!")
Else
    MsgBox (0,"Results", $size)
EndIf

0173032006000041.txt

Share this post


Link to post
Share on other sites

; my test file test.txt on line 1 = EnvSet("Passed", "Total Pass:15")

; launch the script ando open test.txt and put EnvSet("Passed", "Total Pass:15")

; on line 1 and save test.txt

$file = FileOpen("test.txt", 0)
$var = EnvSet("Passed", "Total Pass:15")
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
  ; $line = FileReadLine($file,15)
     $line = FileReadLine($file,1)
        sleep(100)
    If @error = -1 Then ExitLoop
  ; MsgBox(0, "Line read:", $line)
   If StringInStr($line, "Passed") then
    MsgBox(0, "Passed:", "Test Results are Good, Ready to Print") 
exit    
    EndIf
Wend
FileClose($file)

Share this post


Link to post
Share on other sites

tested on your file :

$file = FileOpen("0173032006000041.txt", 0)
;$var = EnvSet("Passed", "Total Pass:15")
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file,15)
;MsgBox(262144, "", $line)
; $line = FileReadLine($file,1)
        sleep(100)
    If @error = -1 Then ExitLoop
  ; MsgBox(0, "Line read:", $line)
   If StringInStr($line, "24") then
    MsgBox(0, "Passed:", "Test Results are Good, Ready to Print") 
exit    
    EndIf
Wend
FileClose($file)

Share this post


Link to post
Share on other sites

Thanks for your feedback. I will try your script. I did find something that you may want to try.

$Passed = "Total        Pass: 24"
$LogFile = FileOpen($v_path&$s_serial&".log",0)
If $LogFile = -1 Then
    MsgBox(0x10, "Fatal Error, File Does Not Exist", "Need to Run ETS Testing")
    Exit
EndIf
;------------------------------------------
; Printing Report from Server Drive U:\
;------------------------------------------
$i = 1
While 1
    $Read = FileReadLine($LogFile, $i)
    If @error Then ExitLoop
    If StringInStr($Read, $Passed) Then
               ;;;; What ever you need done at this point.

tested on your file :

$file = FileOpen("0173032006000041.txt", 0)
;$var = EnvSet("Passed", "Total Pass:15")
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file,15)
;MsgBox(262144, "", $line)
; $line = FileReadLine($file,1)
        sleep(100)
    If @error = -1 Then ExitLoop
 ; MsgBox(0, "Line read:", $line)
   If StringInStr($line, "24") then
    MsgBox(0, "Passed:", "Test Results are Good, Ready to Print") 
exit    
    EndIf
Wend
FileClose($file)

Share this post


Link to post
Share on other sites

look at the help file >> C:\PROGRA~1\AUTOIT3\AUTOIT3.CHM

But WATCH on your $var ERROR :

$file = FileOpen("0173032006000041.txt", 0)
;$var = "Total  Pass: 24" ; 
$var = " Total      Pass: 24" ;  WATCH the space at BEGINNING

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
  ; MsgBox(0, "Line read:", $line)
    If StringInStr($line, $var) Then
        MsgBox(262144, "", "bingo")
    endif
Wend
FileClose($file)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I have not time to test it now .. but here a starting point

this if $Passed = " Total Pass: 24" is true exit the script

else it continues the loop

; EDIT
;$Passed = " Total      Pass: 24"  ; NO
$Passed = " Total       Pass: 24" ; YES
$LogFile = FileOpen("0173032006000041.txt",0)
If $LogFile = -1 Then
    MsgBox(0x10, "Fatal Error, File Does Not Exist", "Need to Run ETS Testing")
    Exit
EndIf
;------------------------------------------
; Printing Report from Server Drive U:\
;------------------------------------------
#CS   
For $i = 1 to 50
    $Read = FileReadLine($LogFile, $i)
MsgBox(262144, "", $read)
    If @error Then ExitLoop
    If StringInStr($Read, $Passed) Then
        MsgBox(262144, "", "bingo")
        exit
             ;;;; What ever you need done at this point.
           EndIf
       next
       
        #ce
      
While 1;use infinite loop since ExitLoop will get called
    $Read = FileRead($LogFile)
;MsgBox(262144, "", $read)
  ;If @error Then ExitLoop
    If StringInStr($Read, $Passed) Then 
;   $Read = FileRead($LogFile)
    MsgBox(262144, "", "bingo")
        ExitLoop
        
    else
        MsgBox(262144, "", "no")
        EndIf
        
;exit
             ;;;; What ever you need done at this point.
               WEnd
    ;  EndIf
Edited by Lapo

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

the web page mess up the $Passed variable

copy and paste " Total Pass: 24" directly from your txt/log file

NOT from here

; EDIT

;$Passed = " Total Pass: 24" ; NO

$Passed = " Total Pass: 24" ; YES

test:

$Passed = " Total Pass: 24"

$Passed = " Total       Pass: 24"
Edited by Lapo

Share this post


Link to post
Share on other sites

You could probably lighten that up a bit, and help with some preventative maintenance:

$Passed = "Total Pass: 24"
$LogFile = "0173032006000041.txt"
While 1
    If StringInStr(StringStripWS(FileRead($LogFile, FileGetSize($LogFile)), 7), $Passed) Then
        MsgBox(262144, "", "bingo")
        ExitLoop
    Else
        MsgBox(262144, "", "no")
    EndIf
WEnd
This worked on my test.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You could probably lighten that up a bit, and help with some preventative maintenance:

$Passed = "Total Pass: 24"
$LogFile = "0173032006000041.txt"
While 1
    If StringInStr(StringStripWS(FileRead($LogFile, FileGetSize($LogFile)), 7), $Passed) Then
        MsgBox(262144, "", "bingo")
        ExitLoop
    Else
        MsgBox(262144, "", "no")
    EndIf
WEnd
This worked on my test.
Yes .. worked here too .. cleaner script also ...

but STRANGE behaviour with spaces here

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0