2 Replies Latest reply on Apr 21, 2014 5:49 AM by WolfShade

    CF9/10: Change file attributes

    WolfShade Level 4

      Hello, everyone,


      Is there a way to change the attributes of a .txt file that already exists?


      For example:  I use CFFILE to write a .txt file that is blank, and supply the "readOnly" attribute.  Later, I want to dynamically add data to the file.  How do I set the .txt file to NOT readOnly so I can add data?  And, conversely, how do I set the attribute back to readOnly?





        • 1. Re: CF9/10: Change file attributes
          BKBK Adobe Community Professional & MVP

          An example on Windows, using 3 steps:


          <cfset path_to_directory="C:\Users\BKBK\Desktop">


          <!--- Create readOnly blank text file --->

          <cffile action="write" attributes="readonly" file="#path_to_directory#\testFile.txt" output="">


          <!--- Disable readOnly attribute --->

          <cffile action="rename" attributes="normal" source="#path_to_directory#\testFile.txt"  destination="#path_to_directory#\testFile.txt">


          <!--- Write some text to file, switching readOnly attribute back on --->

          <cffile action="write" attributes="readonly" file="#path_to_directory#\testFile.txt" output="Some text">



          • 2. Re: CF9/10: Change file attributes
            WolfShade Level 4



            Thanks, BKBK!  I tried using append with attributes, that didn't work.. hadn't thought of rename.  Brilliant!