Jump to content

Problem with _GUICtrlComboBox_AddDir and files with I attribute


Go to solution Solved by Nine,

Recommended Posts

Posted (edited)

Hello everyone,

I'm having trouble with the _GUICtrlComboBox_AddDir function. It does not add to the combox box any files with the I (contents not indexed) file attribute and no other attributes included in $DDL_READWRITE (A archive or R read only, I think), and there is no constant to include (or exclude) them on the Help about this function. There doesn't seem to exist an equivalent attribute on the Microsoft site (https://learn.microsoft.com/en-us/cpp/mfc/reference/ccombobox-class)...

Do someone know the value to include files with that attribute? My problem is that the drive has that attribute enabled on all files and directories, and so the function does not add any files to the combo box unless they have other attributes included in $DDL_READWRITE (A archive or R read only), so I'm getting unexpected lists with missing files.

Is there any constant or syntax for this case that I may have missed?

This problem can be found using the example code on the help file and running it on a directory with files with the I attribute on and no attributes A or R.

Thank you very much :)

Edited by CityGame
  • CityGame changed the title to Problem with _GUICtrlComboBox_AddDir and files with I attribute
  • Solution
Posted

The value of the attribute FILE_ATTRIBUTE_NOT_CONTENT_INDEXED is 0x2000 (8192).  But it does not work with this function.  You will need to add the files manually in the combo.

#include <GUIConstants.au3>
#include <File.au3>

Example()

Func Example()
  GUICreate("ComboBox Example", 400, 296)
  Local $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)

  Local $aList = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES)
  For $i = 1 To $aList[0]
    If BitAND(_WinAPI_GetFileAttributes($aList[$i]), $FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) Then GUICtrlSetData($idCombo, $aList[$i])
  Next

  GUISetState()

  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

 

Posted

Hello, and thank you again for helping me :)

I have changed my code to use the _FileListToArray function and then adding each file to the combobox in a loop, as you showed on your example.

My purpose wasn't to add files with the "I" attribute enabled (sorry if you thought that from my original post) but to add any files regardless of the "I" attribute (just as it happens with compressed files, attribute "C"). The _GUICtrlComboBox_AddDir function with default attributes parameter does not add files with the "I" attribute enabled and no attributes "A" or "R" (probably a bug? of the Windows function that seems to be called on the _GUICtrlComboBox_AddDir code on GUIComboBox.au3... I doesn't seem a problem of the function itself or AutoIt). But the _FileListToArray works perfectly, and if needed, files could still be filtered by their attributes as you showed on your example, so it's a perfect replace.

The result code that now works as expected (just added an error macro check to prevent accessing the files array if there are no files, or the path doesn't exist...) is:

_GUICtrlComboBox_BeginUpdate($idCombo)
_GUICtrlComboBox_ResetContent($idCombo)
$aFiles = _FileListToArray($sPath, "*.txt", $FLTA_FILES)
If (Not @error) Then
    For $iFilesCurrent = 1 To $aFiles[0]
        _GUICtrlComboBox_AddString($idCombo, $aFiles[$iCHDFilesCurrent])
    Next
    GUICtrlComboBox_EndUpdate($idCombo)
EndIf

If (_GUICtrlComboBox_GetCount($idCombo) < 1) Then
    _GUICtrlComboBox_SetCurSel($idCombo, -1)
    MsgBox(64, "Result", "No files found.")
Else
    _GUICtrlComboBox_SetCurSel($idCombo, 0)
    MsgBox(64, "Result", "File(s) found.")
EndIf

Thank you :)

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
×
×
  • Create New...