ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 13th, 2005, 02:21 AM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
Help with commands for reading a file

Hi guys

Here is my issue:

I have a txt file, which contains data like this:

Beleg;79,00
Bicceh;75,00
Blao;56,50
Blitza;59,00
Braincracker;68,00

Want i want to do with this data is to seperate the name and points, and insert it into a access database table. I know how to work out the database issues.

All i really want is the name of the cf commands i need to use for reading the file. Never worked with this kinda stuff, so i just need to commands i have to use. Then the CF documentation should do the rest i hope. Else i get back to ya

Reply With Quote
  #2  
Old August 13th, 2005, 12:25 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,692 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 41 sec
Reputation Power: 53
<cffile> is the tag used to read file data.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old August 13th, 2005, 12:34 PM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
Yeah i got that impression from reading several documents and tutorials.

Now cffile while read the file into a var. How can i from that var, evaluate every single line for Name and points?

Reply With Quote
  #4  
Old August 13th, 2005, 12:48 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,692 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 41 sec
Reputation Power: 53
Here is an example that uses cfsavecontent, but obviously you'll be getting the file data using cffile instead:

<cfsavecontent variable="fileData">
Beleg;79,00
Bicceh;75,00
Blao;56,50
Blitza;59,00
Braincracker;68,00
</cfsavecontent>

<cfoutput>
<cfloop list="#fileData#" index="thisLine" delimiters="#chr(13)##chr(10)#">
<cfset currentPoint = listFirst( thisLine, ';' ) />
<cfset currentCoordinates = listLast( thisLine, ';' ) />
This Point: #currentPoint# -
Coordinate 1: #listFirst( currentCoordinates, ',' )#
Coordinate 2: #listLast( currentCoordinates, ',' )#
<hr>
</cfloop>
</cfoutput>

Reply With Quote
  #5  
Old August 13th, 2005, 01:06 PM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
Im afriad i dont understand your cfsets you do in the loop. Could you explain it futher?

Reply With Quote
  #6  
Old August 13th, 2005, 02:53 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,692 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 41 sec
Reputation Power: 53
This gets the current point, which is everything in front of the semicolon.
<cfset currentPoint = listFirst( thisLine, ';' ) />

This gets the coordinates, which is everything after the semicolon.
<cfset currentCoordinates = listLast( thisLine, ';' ) />

Reply With Quote
  #7  
Old August 13th, 2005, 04:26 PM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
I tried to set it up, and it seems to create no error. Althought i cant find the file.

I uploaded the file to my server which path is /raidpoint/report.txt

It creates this error:

An error occurred when performing a file operation read on file /raidpoint/report.txt.
The cause of this exception was: java.io.FileNotFoundException: \raidpoint\report.txt (The system cannot find the path specified).

My cffile read code is..

<cffile action="read" file="/raidpoint/report.txt" variable="pointlist">

Reply With Quote
  #8  
Old August 13th, 2005, 10:25 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,692 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 41 sec
Reputation Power: 53
<cffile> requires a full system path (like c:\mydir\myfile.txt) (as described in the documentation).

Reply With Quote
  #9  
Old August 14th, 2005, 03:42 AM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
I tried run it on my local server, which execute it perfectly with no problems at all.

Now i would like it to execute it from a remote server. Problem is - I dont really know the path there. How can i run it there?

Reply With Quote
  #10  
Old August 14th, 2005, 10:37 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,692 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 41 sec
Reputation Power: 53
Look at the path functions, such as expandPath().

Reply With Quote
  #11  
Old August 14th, 2005, 01:31 PM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
Thank you very much - It work perfectly

Reply With Quote
  #12  
Old August 14th, 2005, 05:46 PM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
When you think it goes right, it screws up.

I re-wrote this system to upload this data to a database table. It works perfectly. It enters the values perfect. But then it creates an error i dont really know how to explain. But i can start posting the error message:

The value "" cannot be converted to a number

The lines in question is:
Code:
<cfif #getpoints.raidpoints# NEQ #Points#>
<cfset pointdiff = #Points# - #getpoints.raidpoints#>
<cfquery datasource="Evilfis_db">
INSERT INTO rp_txtreport (charname, pointstxt, pointsdiff, condition)
VALUES ('#Charname#','#Points#','#pointdiff#','1')
</cfquery>


What is does is compare the database value #getpoints.raidpoints# to the txt value of the current player #Points#, and then calculate the difference, if any. The specific line the error code highlights is (as shown above):

<cfset pointdiff = #Points# - #getpoints.raidpoints#>

The txt file lines in question is:

Code:
Anthrax;205,00
Aran;29,00 <--- This is calculated
Archimaegrim;230,00 <--- This is getting an error
Ascention;179,00


I have tried to browse though my database for the names near the error, and haven't found anything extraordinary about them compared to others. Anyone have the slightes clue what might be the issue here?

Reply With Quote
  #13  
Old August 14th, 2005, 06:18 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,692 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 41 sec
Reputation Power: 53
One of the variables you're using in your math equation is an empty string, which can't be subtracted from. You can try to use numberFormat() or do a conditional check using isNumeric().

Reply With Quote
  #14  
Old August 14th, 2005, 07:16 PM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
Thats the wierd part, cause i am running this check on every line:

Code:
<cfif Charname NEQ "" AND Points NEQ "" AND IsNumeric(#Points#)>

Reply With Quote
  #15  
Old August 14th, 2005, 07:39 PM
Evilfish Evilfish is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Denmark, Copenhagen
Posts: 57 Evilfish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 7 m 8 sec
Reputation Power: 5
I found out, that it failed getting the points from either database or txt file. 4 entries did fail. I took your advise (good as usual), and validated them through Isnumeric().

Now i can record those that fail without error. Its works now. Thanks again

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Help with commands for reading a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump