Sign in to follow this  
Followers 0
Clay

Using _FileCountLines

4 posts in this topic

Question,

I am using the following snippet of code in a script... but I am encountering some issues. When I use the code without encasing it within a function it works fine... however when I entag it within the function tags it errors out ....i.e "No files/directories matched the search pattern". Is there any know issue with FileFindFirstFile that prevents me from using it with the function below ... or am I doing something wrong or using something wrong?

Func logVaild()
    ;Searches for any file starting with APE in APE_Logs directory
        $parent=StringLeft(@ScriptDir,StringInStr(@ScriptDir,"\",0,-1)-1)
        $tmp =FileFindFirstFile($parent & "\APE_Logs\APE*") 
    ; Check if the search was successful
        If $tmp = -1 Then
            MsgBox(0, "Error", "No files/directories matched the search pattern")
            Exit(2)
        EndIf
        $LogName = FileFindNextFile($tmp)
        $CountLines = _FileCountLines($parent & "\APE_Logs\" & $LogName)
        MsgBox(0, "Error",$LogName & " "& $CountLines )
        FileClose($tmp)
        $tmp = ""
EndFunc

Share this post


Link to post
Share on other sites



Question,

I am using the following snippet of code in a script... but I am encountering some issues. When I use the code without encasing it within a function it works fine... however when I entag it within the function tags it errors out ....i.e "No files/directories matched the search pattern". Is there any know issue with FileFindFirstFile that prevents me from using it with the function below ... or am I doing something wrong or using something wrong?

Func logVaild()
;Searches for any file starting with APE in APE_Logs directory
        $parent=StringLeft(@ScriptDir,StringInStr(@ScriptDir,"\",0,-1)-1)
        $tmp =FileFindFirstFile($parent & "\APE_Logs\APE*") 
; Check if the search was successful
        If $tmp = -1 Then
            MsgBox(0, "Error", "No files/directories matched the search pattern")
            Exit(2)
        EndIf
        $LogName = FileFindNextFile($tmp)
        $CountLines = _FileCountLines($parent & "\APE_Logs\" & $LogName)
        MsgBox(0, "Error",$LogName & " "& $CountLines )
        FileClose($tmp)
        $tmp = ""
EndFunc
At first glance I'm seeing $parent=StringLeft(@ScriptDir,StringInStr(@ScriptDir,"\",0,-1)-1) Depending on where you are running this from it could be a problem because @ScriptDir does not have a trailing backslash so you would be serching one level up from @ScriptDir. Is that where you intended to start?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

At first glance I'm seeing $parent=StringLeft(@ScriptDir,StringInStr(@ScriptDir,"\",0,-1)-1) Depending on where you are running this from it could be a problem because @ScriptDir does not have a trailing backslash so you would be serching one level up from @ScriptDir. Is that where you intended to start?

Yes, that was my exact intent

The structure of my fold is like this.... Main Fold -> which contains subfolders ....two of the sub folders are Functions and APE_Logs..... I want my function stored in Functions to access my logs in APE_Logs, but I can not simply just place the function in Logs Folder (By the way the script works fine as a function in the APE_logs folder), because the logs folder is automatically created if and only if a critical error occurs

In my test environment the APE_logs folder exist.

Edited by Clay

Share this post


Link to post
Share on other sites

ahhhhhhhhhh ok so I figured out what was wrong... The Script calling the Function was in the Main Folder.... so all I had to do was use @ScriptDir & APE_Logs\.... instead of tracing backwards to the from the Functions folder to the Main folder and then to the Logs Folder. Just in case anyone has this issue sometime in the future.

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