amin84 Posted July 20, 2010 Share Posted July 20, 2010 Hi, I'm trying to list the directories under "C:\Users" and I came up with the code below: #Include <File.au3> #Include <Array.au3> $folderList=_FileListToArray("C:\Users", "*", 2) If @Error=1 Then MsgBox (0,"","No Folders Found.") Exit EndIf _ArrayDisplay($folderList,"List") Now the problem is that the code above will list hidden folders "Default" and "Default User" too which I don't want. Is there a way to list only folders that are not hidden? Link to comment Share on other sites More sharing options...
omikron48 Posted July 20, 2010 Share Posted July 20, 2010 You can make your own listing function using FileFindFirstFile and FileFindNextFile. YOu can distinguish between hidden and non-hidden folders with the use of FileGetAttrib. Or you can try the search feature of the forums. There are some file listing algorithms posted here that can be used or modified to suit your purpose. Link to comment Share on other sites More sharing options...
amin84 Posted July 20, 2010 Author Share Posted July 20, 2010 Ok so I used FileGetAttrib but I don't know why it doesn't get the attribs. I don't know what I'm doing wrong. #Include <File.au3> #Include <Array.au3> $folderList=_FileListToArray("C:\Users", "*", 2) If @Error=1 Then MsgBox (0,"","No Folders Found.") Exit EndIf For $i = 1 To $folderList[0] $attrib = FileGetAttrib($folderList[$i]) If @error Then MsgBox(4096,"Error", "Could not obtain attributes.") Else If StringInStr($attrib, "H") Then _ArrayDelete($folderList, $i) EndIf EndIf Next _ArrayDisplay($folderList,"List") Link to comment Share on other sites More sharing options...
omikron48 Posted July 20, 2010 Share Posted July 20, 2010 Using _ArrayDelete in this way is wrong. _ArrayDelete removes the element at the specified index and resizes the array after deletion. Combining that with a For...Next loop will make the loop fail. What happens when an element is deleted is that after the removal, the next element takes the index of the element that was just removed. This makes you skip the processing of the next element after a deletion, not to mention your array is one element shorter after a deletion which will result to an out of bounds array access when a deletion is performed. Link to comment Share on other sites More sharing options...
KaFu Posted July 20, 2010 Share Posted July 20, 2010 You might want to consider excluding System directories as well... #include <File.au3> #include <Array.au3> $path = "C:\temp\" $folderList = _FileListToArray($path, "*", 2) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf For $i = 1 To $folderList[0] If $i > $folderList[0] Then ExitLoop $attrib = FileGetAttrib($path & $folderList[$i]) If @error Then MsgBox(4096, "Error", "Could not obtain attributes.") Else If StringInStr($attrib, "H") Or StringInStr($attrib, "S") Then _ArrayDelete($folderList, $i) $i -= 1 $folderList[0] -= 1 ;_ArrayDisplay($folderList,"List") EndIf EndIf Next _ArrayDisplay($folderList,"List") Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
amin84 Posted July 20, 2010 Author Share Posted July 20, 2010 THANK YOU KaFu. I'm a noob in Autoit n I spent couple of hours n I couldn't figure it out. This can help me a lot. THANKS. Link to comment Share on other sites More sharing options...
amin84 Posted July 21, 2010 Author Share Posted July 21, 2010 Here is a sample for people who might have the same problem I had. This will list all users (depending on the OS) and check if they have hidden or system attrib. If they have, it will remove it from the array. And finally will make a GUI that will list the users in checkbox form. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $usersDis = 24 If @OSVersion = "WIN_XP" Then $path = "C:\Documents and Settings\" Else $path = "C:\Users\" EndIf $folderList = _FileListToArray($path, "*", 2) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf For $i = 1 To $folderList[0] If $i > $folderList[0] Then ExitLoop $attrib = FileGetAttrib($path & $folderList[$i]) If @error Then MsgBox(4096, "Error", "Could not obtain attributes.") Else If StringInStr($attrib, "H") Or StringInStr($attrib, "S") Then _ArrayDelete($folderList, $i) $i -= 1 $folderList[0] -= 1 EndIf EndIf Next $usersFrm = GUICreate("Users", 193, 135, 192, 124) $usersLbl = GUICtrlCreateLabel("Users:", 8, 8, 40, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") For $i = 1 To $folderList[0] $folderList[$i] = GUICtrlCreateCheckbox($folderList[$i], 8, $usersDis, 97, 17) $usersDis += 16 Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
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