Sign in to follow this  
Followers 0
radiererer

How to check accessibility of a folder

7 posts in this topic

Hi,

I'm looking for a possibility to check the accessibility of a folder. Unfortunately I can't use FileExists() for that, because there is no general subfolder or file in the folders, which I want to check. Furthermore I tried FileGetAttrib() but I only get D as output (naturally).

Thanks a lot in advance. :unsure:

Share this post


Link to post
Share on other sites



FileExists works for folder too !

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I know, but I also get a 1 as return value even though there is no permission to open/access the folder. :unsure:

Edited by radiererer

Share this post


Link to post
Share on other sites

For see Access Control List, see this


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Another way to get perms :

#cs ----------------------------------------------------------------------------

     Get Acl By Cacls

    R Read
    C Change (write)
    F Full control
    P Change Permissions (Special access)
    O Take Ownership (Special access)
    X EXecute (Special access)
    E REad (Special access)
    W Write (Special access)
    D Delete (Special access)
    T Not Specified

    (OI) = Object Inherit. ( Files (objects) created in this folder inherit its permissions )
    (CI) = Container Inherit. ( Directories (containers) created in this folder inherit its permissions )
    (IO) = Inherit Only. ( The permission does not apply to the directory, but only its subdirectories )

#ce ----------------------------------------------------------------------------

$_CaclsPath = @SystemDir & "\CACLS.exe"
_GetAclByCacls ( @MyDocumentsDir )

Func _GetAclByCacls ( $_FilePath )
    $_Run = FileGetShortName ( $_CaclsPath ) & ' "' & $_FilePath & '"'
    ConsoleWrite ( '--------- $_Run : ' & $_Run & @Crlf )
    $_Pid = Run ( $_Run, '', @SW_HIDE, 4 )
    Local $_StdoutRead=''
    While ProcessExists ( $_Pid )
        $_StdoutRead = StringStripWS ( StdoutRead ( $_Pid ), 7 )
        If Not @error And $_StdoutRead <> '' Then _
        ConsoleWrite ( "-->-- STDOUT read : " & @CRLF & $_StdoutRead & @Crlf )
    Wend
EndFunc ;==> _GetAclByCacls ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Another way to get perms :

#cs ----------------------------------------------------------------------------

     Get Acl By Cacls

    R Read
    C Change (write)
    F Full control
    P Change Permissions (Special access)
    O Take Ownership (Special access)
    X EXecute (Special access)
    E REad (Special access)
    W Write (Special access)
    D Delete (Special access)
    T Not Specified

    (OI) = Object Inherit. ( Files (objects) created in this folder inherit its permissions )
    (CI) = Container Inherit. ( Directories (containers) created in this folder inherit its permissions )
    (IO) = Inherit Only. ( The permission does not apply to the directory, but only its subdirectories )

#ce ----------------------------------------------------------------------------

$_CaclsPath = @SystemDir & "\CACLS.exe"
_GetAclByCacls ( @MyDocumentsDir )

Func _GetAclByCacls ( $_FilePath )
    $_Run = FileGetShortName ( $_CaclsPath ) & ' "' & $_FilePath & '"'
    ConsoleWrite ( '--------- $_Run : ' & $_Run & @Crlf )
    $_Pid = Run ( $_Run, '', @SW_HIDE, 4 )
    Local $_StdoutRead=''
    While ProcessExists ( $_Pid )
        $_StdoutRead = StringStripWS ( StdoutRead ( $_Pid ), 7 )
        If Not @error And $_StdoutRead <> '' Then _
        ConsoleWrite ( "-->-- STDOUT read : " & @CRLF & $_StdoutRead & @Crlf )
    Wend
EndFunc ;==> _GetAclByCacls ( )

That's much easier und more understandable for a noob like me. Thanks a lot!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

How about something like this :unsure:?

$sPath = @ScriptDir
ConsoleWrite(_Directory_Is_Accessible($sPath) & @CRLF)

$sPath = "C:\Windows\System32\appmgmt\MACHINE\"
ConsoleWrite(_Directory_Is_Accessible($sPath) & @CRLF)

Func _Directory_Is_Accessible($sPath)
    If Not StringInStr(FileGetAttrib($sPath), "D", 2) Then Return SetError(1, 0, 0)
    Local $iEnum = 0
    While FileExists($sPath & "\_test_" & $iEnum)
        $iEnum += 1
    WEnd
    Local $iSuccess = DirCreate($sPath & "\_test_" & $iEnum)
    Switch $iSuccess
        Case 1
            DirRemove($sPath & "\_test_" & $iEnum)
            Return True
        Case Else
            Return False
    EndSwitch
EndFunc   ;==>_Directory_Is_Assesible
Edited by KaFu

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