Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default cffile and read

    I am working on a simple paperless transaction system, and for some reason I
    can not get the attribute action='read' with cffile to work. I have read over
    hte live docs and they are not very helpful. I have the variable attribute set
    to test. But when I run the page it displays all the text in the .txt doc. How
    can I set it up so that it only reads the var set to test.

    rottmanja Guest

  2. Similar Questions and Discussions

    1. CFFILE ACTION=READ question
      Hey Gang- I have a .cfm page that reads a text file using "cffile action=read" that I parse, read, loop through, etc. When I loop through the...
    2. CFFile read not working through mapped drive
      I'm trying to use cffile to read a text file on a remote server through a mapped drive (d:) but getting the error : An error occurred when...
    3. cffile read and tab delimited files
      I am attempting to read a tab delimited file which contains 11 pieces of data seperated by ten tab characters. In some cases there may be missing...
    4. File system get auto change from read-write to read-oly
      I have a very strange file system with OS Redhat 7.2 The file system is read-write, but some how it randomly changes to read-only at any time....
    5. Read & Read/Write Groups
      I am trying to achieve a solution to a (hopefully) simple scenario. I have a Solaris 9 server that is going to be used for sharing files. I...
  3. #2

    Default Re: cffile and read

    i dont undestand what you want. since you have not posted trouble code i can
    only send sample code.

    cffile is very simple to use. use cftry/cfcatch to trap file reading errors.

    <cfset my_file="">
    <cftry>
    <cffile action="READ" file="d:\wwwroot\myfile.txt" variable="my_file">
    <cfcatch type="Any">
    error occured while reading file
    </cfcatch>
    </cftry>

    <cfif my_file neq "">
    file content:
    #my_file#
    <cfelse>
    file content:
    file reading failed
    </cfif>

    cheers, kim

    kim il sung Guest

  4. #3

    Default Re: cffile and read

    I got it to work after going over a few things in my head. But how ever it
    brings up another problem that I have seen with other aspects of cf. I have
    attached my code below so you can understand what i am talking about. When I
    use cfdirectory to create a new directory based on the file that cffile reads,
    it creates a directory with weird chars after the data from the read file. EX.
    it creates a directory with S050123 and two boxes behind it. The S050123 is
    correct, but the boxes should not be there. (note I can not paste the boxes in
    here for some reason)

    <!-- Checks directory for .txt files -->
    <cfdirectory action="list" name="chkDir" directory="#dir#" filter="*.txt">
    <!-- Setting some Vars -->
    <cfparam name="fileExists" default="no">
    <!-- Reads files for file number -->
    <cffile action="Read"
    file="#dir##chkDir.Name#"
    variable="readText">
    <cfif DirectoryExists("#dir##readText#")is "NO">
    <cfif FileExists("#dir##chkDir.Name#") is "Yes">
    <cfset fileExists="yes">
    <!-- Creates a new directory -->
    <cfdirectory action="create"
    directory="#dir##readText#" mode="">

    <!-- Moves Files to the newly create directory -->
    <cffile
    action = "move"
    source = "#dir##chkDir.Name#"
    destination = "#dir##readText#"
    mode = "777">
    <!-- Renames the .txt file to the file number -->
    <cffile
    action = "rename"
    source = "#dir##readText#"
    destination = "#dir##readText#"
    mode = "777">

    </cfif>
    </cfif>
    <cfoutput query="getDir">
    The files (#getDir.Name# exist on the server and have been moved to)<br>
    <br>
    The files are (#readText#)
    </cfoutput><br>

    rottmanja Guest

  5. #4

    Default Re: cffile and read

    Well I figured it out afterwards, I had forgotten to use the trim fucntion.
    rottmanja Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139