• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF9/10: Change file attributes

LEGEND ,
Apr 18, 2014 Apr 18, 2014

Copy link to clipboard

Copied

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?

V/r,

^_^

Views

399

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 19, 2014 Apr 19, 2014

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=

...

Votes

Translate

Translate
Community Expert ,
Apr 19, 2014 Apr 19, 2014

Copy link to clipboard

Copied

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">

Done!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 21, 2014 Apr 21, 2014

Copy link to clipboard

Copied

LATEST

!!!

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

V/r,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation