Jump to content

Recommended Posts

Posted

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

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.

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...