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,
^_^
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=
...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!
Copy link to clipboard
Copied
!!!
Thanks, BKBK! I tried using append with attributes, that didn't work.. hadn't thought of rename. Brilliant!
V/r,
^_^