Jump to content

Recommended Posts

Posted (edited)

Well, it seems I can use @error to do what I wanted... Now, a new question!

When I have the time and date in this format, how will I be able to date add to it, as well as determine the day of the week.

Jul 19, '06 11:52

Edited by brodie28
Posted (edited)

Counting lines in a file can be done with FileCountLines, while you can add to your

date with DateAdd. Btw, with that date-fomat you have to use the string-functions

to get it to the proper format, so that DateAdd can use the information.

Edited by Helge
Posted

This was my own version of _FileCountLines, needed it for another other script I was working on

Just change the $filename var to a file you want to test this against

(Requires beta for this one)

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
    Local $a_count
    Local $file_name = @ScriptDir & "\test.au3"
    $a_count = _FileCountLines($file_name) ; get the count of all lines only
    MsgBox(0, "Count", $a_count)
    
    $a_count = _FileCountLines($file_name, ";", True) ; return array containing count of commented/un-commented/all lines
    If IsArray($a_count) Then
        MsgBox(0, "Count", "# of Comment Lines: " & @TAB & $a_count[1] & @LF & _
                "# of Un-Commented Lines: " & @TAB & $a_count[2] & @LF & _
                "The Total # of Lines: " & @TAB & $a_count[3])
    Else
        MsgBox(0, "Count", $a_count)
    EndIf
    
    $a_count = _FileCountLines($file_name, ";") ; return count of commented lines
    MsgBox(0, "Count", $a_count)
    
    $a_count = _FileCountLines($file_name, ";", Default, 2) ; return count of un-commented lines
    MsgBox(0, "Count", $a_count)
EndFunc   ;==>_Main

Func _FileCountLines($sFilePath, $sCommentChar = "", $b_ReturnArray = False, $i_ReturnCount = 1)
    Local $a_counts[4]
    Local $N = FileGetSize($sFilePath) - 1
    If @error Or $N = -1 Then Return 0
    If @NumParams = 1 Then Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1
    
    Local $s_text = StringReplace(StringReplace(FileRead($sFilePath, $N), " ", ""), @TAB, "")
    Local $sReplaced = StringReplace(@LF & StringAddCR($s_text), @LF & $sCommentChar, $sCommentChar, 0, 1)
    
    $a_counts[0] = 3
    $a_counts[1] = @extended;number of commented lines
    $a_counts[2] = StringLen($sReplaced) - StringLen($s_text);number of un-commented lines
    $a_counts[3] = $a_counts[1] + $a_counts[2];total number of lines
    
    If $b_ReturnArray Then
        Return $a_counts
    Else
        If $b_ReturnArray <> 1 And $b_ReturnArray <> 2 Then $b_ReturnArray = 1
        Return $a_counts[$i_ReturnCount]
    EndIf
EndFunc   ;==>_FileCountLines

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...