Technical support and scripting issues
Moderators: Dorian (MJT support), JRL
-
MGuyM
- Junior Coder
- Posts: 36
- Joined: Tue Jul 24, 2007 12:59 am
Post
by MGuyM » Wed Jul 23, 2008 4:38 pm
I'm currently running a process that reads each line of a file and then performs some action on the data retrieved:
Code: Select all
Label>Start
ReadLn>%strFileToProcess%.CSV,X,Line
If>Line=##EOF##,End_Script
Separate>Line,comma,LineValue
In my process, I'm incrementing X each time. What I'd like to know is how can I determine the total number of lines in my File so that I can produce a display window to show how many records of the total have been processed?
I've been reading upon on the different ways of looping, but I can't quite figure out if there is one that can determine the total number of records in the file (unless I read and loop through the entire file before I begin processing, which I think would be a duplicate effort, but may be the only way).
Any ideas?
Thanks!
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Wed Jul 23, 2008 5:55 pm
ReadFile>filename,filedata
Separate>filedata,CRLF,lines
MessageModal>Number of lines: %lines_count%
-
MGuyM
- Junior Coder
- Posts: 36
- Joined: Tue Jul 24, 2007 12:59 am
Post
by MGuyM » Wed Jul 23, 2008 6:01 pm
Thanks Marcus!
Just had another thought.... Is there a Size Limitation to the Reading of a File? My File could have up to 100000 Lines in it and I just wonder if it would be too big?
Thanks!
-
JRL
- Automation Wizard
- Posts: 3526
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Wed Jul 23, 2008 7:54 pm
I've used readfile to read files that are around 10 meg. Not that there is not a size limit on readfile> it probably has more to do with your computer's capability though and not a limit imposed by readfile>.
If Readfile>/Separate> is slow for you, see
this thread, there are two more possibilities discussed.
-
Me_again
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Post
by Me_again » Thu Jul 24, 2008 12:57 am
If you are dealing with very large files you may want to check whether the additional time needed for the extra step of scanning scanning the file to determine the number of lines is really worthwhile.
-
pasdad1
- Junior Coder
- Posts: 21
- Joined: Wed Nov 17, 2004 1:09 am
Post
by pasdad1 » Mon Jul 28, 2008 5:39 pm
When dealing with VERY LARGE files, what I have done is to find out the size of the file in bytes (using the MS FileSize> command or DOS DIR command) and then pick a reasonable average line length to divide into this.
This gives a reasonably accurate guess as to the number of lines. The FileSize> or DOS DIR commands return INSTANTLY because they don't have to read the file first.... this info is already stored in the directory structure by the operating system.
On VERY LARGE files it usually doesn't matter that the guess by this method is off by a little, because you are usually only using this info to update a status bar or percentage done type of thing. Of course as you are actually processing the file (reading one line at a time in a loop) you are counting the lines actually processed, and comparing this to your estimated, computed total of lines.
-
JRL
- Automation Wizard
- Posts: 3526
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Mon Jul 28, 2008 6:02 pm
Great idea pasdad1... I'll try it the next script I have needing line count. Being off a little won't hurt my feelings, usually I put the count in a message box as Line X of XXXX just so I have a feel for when I'll get my computer back.