|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
<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 |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
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> |
|
#5
|
|||
|
|||
|
Im afriad i dont understand your cfsets you do in the loop. Could you explain it futher?
|
|
#6
|
|||
|
|||
|
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, ';' ) /> |
|
#7
|
|||
|
|||
|
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"> |
|
#8
|
|||
|
|||
|
<cffile> requires a full system path (like c:\mydir\myfile.txt) (as described in the documentation).
|
|
#9
|
|||
|
|||
|
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? |
|
#10
|
|||
|
|||
|
Look at the path functions, such as expandPath().
|
|
#11
|
|||
|
|||
|
Thank you very much - It work perfectly
![]() |
|
#12
|
|||
|
|||
|
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? |
|
#13
|
|||
|
|||
|
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().
|
|
#14
|
|||
|
|||
|
Thats the wierd part, cause i am running this check on every line:
Code:
<cfif Charname NEQ "" AND Points NEQ "" AND IsNumeric(#Points#)> |
|
#15
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Help with commands for reading a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|