Ask a Jedi: Getting file permissions

Jibu asks:

I am using Linux(Railo) as my server and I want to show the files permission(mode) in a directory as -rwxr-xr-x (eq.). How can I show this?

We can set file permission using FileSetAccessMode() but how to get this permission like "-rwxr-xr-x" this to show in a page ?

So I don’t know if this is the best answer, but it’s what I was able to glean from Google this morning. Java 6 does have some functions that can tell you if the current application can read, write, and execute a file. (See the File doc.) But as far as I can tell, this only applies to the user that the application is running as.

I found more than a few search results though that mentioned using a system specific command. In ColdFusion that means cfexecute. Consider this sample:

<cfexecute name="ls" arguments="-l /Users/ray/lhp.txt" variable="result" timeout="99" />

This returns:

-rw-r--r-- 1 ray ray 6386 May 12 2007 /Users/ray/lhp.txt

This is simple enough to parse with a string function:

<cfoutput>#listFirst(result, chr(32))#</cfoutput>

By treating the result as a list, I can then end up with just the permissions. Obviously this won’t run on Windows, but you get the idea.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments