Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change File Attributes On the Fly

Status
Not open for further replies.

jalbao

Programmer
Nov 27, 2000
413
US
It's been a while since I used ColdFusion - I have forgotten many concepts :(

How, if possible, can I script ColdFusion to change the file
attributes (MODE) of a specific file located in CF Server's root directory(running on Linux)?

For example:
I have a file named "myfile.txt" located in the /var/chroot/html/ web root directory. The "myfile.txt" only has "Read" rights. Now, in my CF app, I want a user to be able to Delete the "myfile.txt" file (i.e.<cffile action="delete"....>. However, CF will fail on the execution
of the <cffile action="delete"...> tag since the file doesn't have "Write" rights.

Ideally, prior to deleting a file, I would like to check it's attributes. If the file does not have 'Write" rights, then I would like to change the rights (file attributes) of the file to "777" (rwx). Is this possible? If so, how?

By the way, it's nice to see a lot of the familiar names that are still making this forum tick! - Can you believe we're getting close to 10 years on this forum!
 
See if this works:

First take the file and do a cffile action="write" -
<cffile action="write" file="myfile.txt" mode=777>

Then, do a cffile action="delete" -
<cffile action = "delete" file="myfile.txt">

Now the file should be deletable cause you chnaged the mode.

This is untested, so let us know if this works.


____________________________________
Just Imagine.
 
I'm not on a linix system here so there may be a little tweeking to do but this works for me:

Code:
<cfset myFile = ExpandPath('./files.cfm')>
<cfset fileObj = createObject("java", "java.io.File")>

<cfset fileObj = createObject("java", "java.io.File").init(myFile)>

<cfif NOT fileObj.canWrite()>
	<cffile action="copy" source="#myFile#" destination="#expandPath('./mynewfile.cfm')#" mode="777">
</cfif>

The deleting part you're still gonna have a problem with as the user won't have the permissions, so maybe take the suggestion from above and combine the two.

Hope this helps!

Tony
 
I attempted to do the "Write" action, but I received the following error messages:

"An error occurred when performing a file operation WRITE on file.

The cause of this exception was: java.io.FileNotFoundException: /var/chroot/home/html/literature2.txt (Permission denied)."

I have a feeling that there is no solution to my problem.

The bummer is, I'm on a shared Linux server and the way that my host has the server setup is to NOT have child directories/files inherit the permissions of their parent. Which implies that I can't just set the permissions of the directory that stores all my literature files and have those files inherit the permissions (777).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top