Counting lines of text in a file, missing something on the syntax?

7 posts in this topic

xuzo 0

I've looked at the example but not working for me so I created a text file with 3 lines in it.

Trying to run it but shows 0, I know there is probably just a few characters wrong...

#include Local$CountLines=_FileCountLines("D:\xtra-df\AutoIT\examples_bruno\count_file_lines\input.txt")MsgBox(64,"Counting the lines in the text file","There are "&$CountLines&" lines in the input.txt file.")Exit

Share this post

Link to post

Share on other sites

Melba23 2,481

It works fine for me. Are you sure that the file path is correct? Try using FileExists to check.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Share this post

Link to post

Share on other sites

xuzo 0

Yes was the wrong path...trying to organize everything in different folders!

Trying to set the path so the file sits in the same folder as the AutoIT file, I have the syntax wrong as usual, please have a look:

#includeLocal$CountLines=_FileCountLines(@ScriptDirinput.txt") ; not sure how to use the @ScriptDir code
MsgBox(64, "Counting the lines in the text file", "There are " & $CountLines & " lines in the input.txt file.")
Exit

That would avoid path problems in the future! Just keep everything self contained

Share this post

Link to post

Share on other sites

water 1,637

BTW: To avoid errors you need to check if an operation was successful. The help file describes how a function returns an error (either by setting the return value to 0 or by setting the macros @error and @extended).