Sign in to follow this  
Followers 0
objectivescott

Checking For Write Access On Folders

8 posts in this topic

I need to have my script check a folder to ensure it is writable before the script attempts to write data files there. Does anyone have a good way of doing this already?

Up to this point, I've been using the FileOpen code and getting its return value of

-1 if the folder is not writable. The problem with this is, the script must create a file there first in order to give me this answer. I would like a clean way of checking a folder for writablility.

Any thoughts?

-S. Williams

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

Can't you just erase the file after words?

;Folder Write-Protection Checking example by AutoElectric
$Folder = TheFolder

$Protected = 1
$Handle = FileOpen($Folder&\Test,2)

If $Handle <> -1 then
     FileDelete($Folder&\Test)
     $Protected = 0
EndIf

I don't see any other solution.

Maybe there is a command line tool that will check it but it is not of my knowledge.

Edit: Appearantly the forum does not allow font styles to be embedded within code tags.

Edited by AutoElectric

From the book of AutoElectric"Do not accuse another man, without proof, or you too will be accused", Morals 4:21The book of AutoElectric is MY book of morals, and follows biblical teachings.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Maybe there is a command line tool that will check it but it is not of my knowledge.

Yes it's called 'attrib' :)

Would just manually setting the folder to writeable work?

RunWait(@ComSpec & ' /c attrib -R',@DirectoryYouWantToCheck,@SW_HIDE)
Edited by Alterego

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yes it's called 'attrib'  :)

Would just manually setting the folder to writeable work?

RunWait(@ComSpec & ' /c attrib -R',@DirectoryYouWantToCheck,@SW_HIDE)

<{POST_SNAPBACK}>

The Autoit inbuilt functions maybe more suited, to the task? :D

FileGetAttrib ( "filename" )
FileSetAttrib ( "file pattern", "+-RASHNOT" [, recurse] )
Edited by MHz

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

and there ya' go....  :)

<{POST_SNAPBACK}>

Thanks guys. The thing is...the folder may not even be available. For example, the folder may reside on a server which is currently offline or unavailable. Attrib will not work for this. That is why I was careful to say "writable"...as opposed to "have write permissions".

Creating a file and then deleting it afterwards is a little silly and unclean I think.

Edited by objectivescott

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I'm not following. If you are able to create a folder on a computer you are absolutely able to check the attributes of folders on that computer as well...

Edit: able to create a file

Edited by Alterego

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I thought it was attrib, but I didn't seem to see the relation ship between non-writtable and read only. I thaught write-protected folders were set by some other means.

Edited by AutoElectric

From the book of AutoElectric"Do not accuse another man, without proof, or you too will be accused", Morals 4:21The book of AutoElectric is MY book of morals, and follows biblical teachings.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0