Hello,
I need help. How can I count how many rows inside a .csv file? Also is there a easy way to compare a .csv file and have it output the results to a file?
Thanks!
Printable View
Hello,
I need help. How can I count how many rows inside a .csv file? Also is there a easy way to compare a .csv file and have it output the results to a file?
Thanks!
You can achieve this by using a FileSystemObject object. Here's a sample function that will return the line count for a file. You will need to add areference to the Microsoft Scripting Runtime library in order for this to run.
VB Code:
Function Count_Lines(FilePath As String) As Long Dim fsoFile As Scripting.FileSystemObject Dim fsStream As Scripting.TextStream 'Create a new File system Object Set fsoFile = New Scripting.FileSystemObject 'Open the file for reading Set fsStream = fsoFile.OpenTextFile(Filename:=FilePath, IOMode:=ForReading) 'Move to the bottom of the file Do Until fsStream.AtEndOfStream fsStream.SkipLine Loop 'Return the current line number, 'Which will equal the count as 'we are at the end of the file Count_Lines = fsStream.Line 'Clear Object Variables Set fsStream = Nothing Set fsoFile = Nothing End Function
Hey thanks for the reply. I'll see if this does the trick. 1 last question... how can I compare 2 excel files..? Do I compare row by row?
That depends, what do you want to compare?
OK.
Heres the deal... I dont have good VB and I'm trying to write a utility that takes 2 excel files (.CSV) and compare them to make sure they are the same. And then write the diffs out to a txt file as a report. Noone here has VB skills and I have very little... PLEASE HELP. Thanks!
Since .csv is just a text file, one option is to read each file into byte arrays and then compare the bytes in a loop. Also, seems to me there used to be a DOS function to do binary compare of two files.............Quote:
Originally Posted by craigheartley
A DOS functgion wich is called FC
Type help FC for more info