PDA

View Full Version : [ASP] Delimited Files



Digitalosophy
March 5th, 2007, 04:11 PM
My ultimate goal is to open a text file database (.txt or .csv)either tab delimted or comma and count the records. Once that is done I can proceed with what I need to do with the data.

I'm doing ok but am kind of stuck right now.

1. Open a text file (done)
2. Read it's contents (done)
3. Determine the delimeter (not done)
4. Count the records in the file (not done because of delimeter)

I'm using TextStream and what happening is the .Line command seems to be counting the tab delimeters as records :cantlook:

A solution I though of was to search for the delimeter and replace it with a different character, but this may lead to more issues further down the road with the application.

So I'm basically looking for someone to shed some light and toss me some advice on how they would go about doing this. Any links would be great - I can't seems to find anything usefull on google or my favorite resource sites.

Here's the current code I am working with


<%
set fsObj = Server.CreateObject("Scripting.FileSystemObject")

file_extension = (fsObj.GetExtensionName(file_name))

if (fsObj.FileExists(file_path & file_name)) = true Then
Response.Write "File: " & file_name & " exists" & "<br>"
Response.Write "The file extension is ." & file_extension & "<br><br>"

Set file_contents = fsObj.OpenTextFile(Server.MapPath(file_name),1)
Response.Write "File Contents: " & "<br>"
Response.Write "Headers are: " & "<br>"
Response.Write "<b>" & (file_contents.ReadLine) & "</b><br><br>"
Response.Write(file_contents.ReadAll) & "<br><br>"
Response.Write "There are " & file_contents.Line & " records " & file_name
file_contents.close
Else
Response.Write "File: " & file_name & " does not exist"
End if

set fsObj = Nothing
%>


Thanks :kommie:

kirupa
March 5th, 2007, 04:53 PM
To delimit based on tabs, try \t instead. Hopefully that works out...unless I misread your question :afro:

Digitalosophy
March 5th, 2007, 04:59 PM
To delimit based on tabs, try \t instead. Hopefully that works out...unless I misread your question :afro:

I'm sorry K I don't follow. You say try /t instead, but instead of what?

bwh2
March 5th, 2007, 05:06 PM
i don't know anything about ASP. but i can offer my PHP or Perl approach, which may help.

are you explicitly defining the column and line delimiters? or are you trying to dynamically figure them out?

Digitalosophy
March 5th, 2007, 05:13 PM
i don't know anything about ASP. but i can offer my PHP or Perl approach, which may help.

are you explicitly defining the column and line delimiters? or are you trying to dynamically figure them out?

Well I won't know how many columns exist or how the file is demilited (i've been spelling it wrong this whole time :lol:). Basically the user uploads a mailing list database and I need to count all their records to give them a price quote.

I'm going to assume the file is either tab or comma delimited (or do you think assuming that is a mistake)?

Digitalosophy
March 5th, 2007, 05:37 PM
LOL

well it turns out the code below didn't work because when I created the database file I had 28 rows selected, so although they were blank it still counted them.

That doesn't solve all my problems but it gets me out of this standstill.

Bwh2 I'm still interested in your methodology :)

bwh2
March 5th, 2007, 05:42 PM
well, if you just want to count the records you can probably ignore the column delimiters. instead, just focus on the line delimiters, which is probably "\r\n" or just "\n".

Digitalosophy
March 5th, 2007, 05:55 PM
Gotcha, yea so far everything I'm trying to do is working.

Thanks fellas.