Jump to content

How to check accessibility of a folder


Recommended Posts

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:

Link to comment
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

Link to comment
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!
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

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