radiererer Posted May 15, 2011 Posted May 15, 2011 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.
wakillon Posted May 15, 2011 Posted May 15, 2011 FileExists works for folder too ! AutoIt 3.3.18.0 X86 - SciTE 4.4.6.0 - WIN 11 24H2 X64 - Other Examples Scripts
radiererer Posted May 15, 2011 Author Posted May 15, 2011 (edited) I know, but I also get a 1 as return value even though there is no permission to open/access the folder. Edited May 15, 2011 by radiererer
wakillon Posted May 15, 2011 Posted May 15, 2011 For see Access Control List, see this AutoIt 3.3.18.0 X86 - SciTE 4.4.6.0 - WIN 11 24H2 X64 - Other Examples Scripts
wakillon Posted May 15, 2011 Posted May 15, 2011 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.18.0 X86 - SciTE 4.4.6.0 - WIN 11 24H2 X64 - Other Examples Scripts
radiererer Posted May 15, 2011 Author Posted May 15, 2011 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!
KaFu Posted May 15, 2011 Posted May 15, 2011 (edited) How about something like this ? $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 May 15, 2011 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now