Jump to content

Multiple filters for ShellFolder object?


Recommended Posts

  • Moderators

Hi all,

I am using a ShellFolder object to get a listing of the content - as shown in this much shortened extract from the code:

Local $oShellApplication = ObjCreate("Shell.Application")
Local $oShellFolder = $oShellApplication.NameSpace($sPath)
Local $oShellFolderItems = $oShellFolder.Items()
Local $oShellFolderItemsFilterFlags = AsRequired
$oShellFolderItems.Filter($oShellFolderItemsFilterFlags, "*")
For $oShellFolderItem In $oShellFolderItems

But although I can successfully use a single filter ("*.au3") to limit the returned items I am unable to find a way to set multiple filters for the returned items (such as "*.au3;*.a3x"). This is forcing me at present to get every item in the folder and then filter them in AutoIt code using a suitable RegEx, which obviously leads to a serious reduction in execution speed.

Does anyone know of a way to use multiple filters when using .Filter to list the items so that I can avoid the AutoIt filter code?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Seems to work for me:

Local $oShellApplication = ObjCreate("Shell.Application")
Local $oShellFolder = $oShellApplication.NameSpace(36)  ; this is c:\windows.
Local $oShellFolderItems = $oShellFolder.Items()
Local $oShellFolderItemsFilterFlags = 64
$oShellFolderItems.Filter($oShellFolderItemsFilterFlags, "*.exe;*.log")
For $oShellFolderItem In $oShellFolderItems
    ConsoleWrite ($oShellFolderItem.name & @CRLF)
Next

Lists all *.exe and *.log from my windows-dir.

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

  • Moderators

Marc,

I though that I had tried all the sensible delimiters - but obviously not! Thanks a lot.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

mikell,

Go and look inside that function - all the filtering is done via Regexes in AutoIt code, so I could pick any delimiter I wanted. I thought I had tried semi-colons as a delimiter in the ShellFolder case too - along with commas, "|" and lots of others - but obviously I had not. My bad.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

mikell,

No probs.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

1 hour ago, mikell said:

Melba,
Sorry. I was just joking a little, please don't care  :)

We were many who wanted to joke, i mean, Melba actually starting a thread asking a question, unheard of :D

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

2 hours ago, mikell said:

I was just joking a little

Really ?  I thought you were seriously serious.  Melba you should ban him !

Maybe someone may think I was serious too :lol:

Edited by Nine
Link to comment
Share on other sites

  • Moderators

Werty & others,

Never be afraid to joke - I enjoy a laugh as much as the rest of you, particularly when the joke is of my own making!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hi again,

This time I am looking for a way to exclude specified items from the return. Google is not being my friend at all - so any offers from you guys?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23 try this :

Local $oShellApplication = ObjCreate("Shell.Application")
Local $oShellFolder = $oShellApplication.NameSpace("C:\Windows")
Local $oShellFolderItems = $oShellFolder.Items()
Local $oShellFolderItemsExcl = $oShellFolder.Items()
$oShellFolderItems.Filter(0x40, "*")
$oShellFolderItemsExcl.Filter(0x40, "*.exe;*.log")
For $oShellFolderItem In $oShellFolderItems
  For $oShellFolderItemExcl in $oShellFolderItemsExcl
    If $oShellFolderItem.name = $oShellFolderItemExcl.name Then ContinueLoop 2
  Next
  ConsoleWrite ($oShellFolderItem.name & @CRLF)
Next

 

Edited by Nine
Link to comment
Share on other sites

@Melba23
This script seems to be a little bit faster:

#include <StringConstants.au3>

Global $hdlTimer = TimerInit()
Global $oShellApplication = ObjCreate("Shell.Application")
Global $oShellFolder = $oShellApplication.NameSpace("C:\Windows")
Global $oShellFolderItems = $oShellFolder.Items()
$oShellFolderItems.Filter(0x40, "*")

For $oShellFolderItem In $oShellFolderItems
    If StringRegExp($oShellFolderItem.Name, '(?<!exe|log)$', $STR_REGEXPMATCH) Then ConsoleWrite($oShellFolderItem.Name & @CRLF)
Next

ConsoleWrite("Task completed in " & Round(TimerDiff($hdlTimer)/1000, 2) & " seconds." & @CRLF)

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

23 minutes ago, Nine said:

That will not work if filter consists on multiple wild cards like a "?ind*,*" .

All depends on how do you want to manage your filters... RE are quite flexibles to give the user what he/she needs.
For example, the filter you proposed above could be easily translated in:

.?ind.*,.*

:)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Agree but you would need to modify your script for each filter.  I don't think it is the way it should be done.  You need to create a general RE for all possible filters.  I believe it could be done, but why investing such an effort (risking some bugs) when Windows can do it for you, even if it costs a few more ms...

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...