Select multiple files, press hotkey to add those files to Global File Filters

I would like to be able to select multiple files in a Lister, then press a hotkey or a toolbar button which would automatically add those files to the Filename Global Filters (I want the selected files to be hidden).

I am currently copying-and-pasting each file name, one at a time, into a .txt file, like so:

(file 1|file 2|file 3|file 4|file 5) etc., then copying-and-pasting the (file 1|file 2|file 3|file 4|file 5) list into the Filename: Global Filter edit field. Is there a fairly simple way of doing this? Thank you for your help.

P.S. I really like the new forum design.

Commands and scripts can set the global filter, but I don't think there is currently a way for them to find out what it currently is.

We could add that in a future version. It wouldn't be perfect since there isn't really a general way to add something to a regex or wildcard (they could be absolutely anything), but if you know they'll always be a simple (x|y|z) style pattern then that's easy enough for a script to add to.

It's quite unusual to want to hide a lot of filenames globally, though, and a complex wildcard in the global filter may start to slow things down as everything that ever gets displayed has to be tested against it. (Although impact is probably only slight, and only in theory; I haven't measured it and may be worrying about nothing.)

Could there be a better way to do what you want, such as using the hidden attributes on specific files, or only filtering them out in certain folders where they'll appear?

Opus 12.3.6 beta introduces a change that should allow this now:

  • Added DOpus.Filters script property to provide access to global filter settings.

I found a roundabout way of doing what I wanted to do. I click on all of the files in a Lister that I want to hide (via the Global Filter for files), then press CTRL + N (which I have set to copy file names). Then I simply press CTRL + V (which creates a "Clipboard Text.txt" file). I open that file in Notepad++, then run a macro I created which lines up the file names, properly formatted, and ready to paste into the Global Filter edit field.

Thank you for taking the time to respond to my question.

It's quite unusual to want to hide a lot of filenames globally

Oh, man, believe me, I am unusual :grin:

Here's a script that can do it automatically as long as you have the current beta (12.3.6). You can add this to a button or hotkey.

Add Filenames To Global Filter.dcf (4.2 KB)

For reference, the script code is below.

Option Explicit

Function OnClick(clickData)

	Dim flt, vecFiles, vecDirs, f, cmd, c
	Set flt = DOpus.filters
	Set vecFiles = DOpus.Create.Vector
	Set vecDirs = DOpus.Create.Vector

	c = 0
	for each f in clickData.func.command.files
		if f.is_dir Then
			vecDirs.push_back(f.name)
		else
			vecFiles.push_back(f.name)
		end if
		c = c + 1
	next

	if c > 0 Then
		clickData.func.command.ClearFiles
		if not(vecDirs.empty) then AddToFilter flt.folder, vecDirs, clickData.func.command, "GLOBALHIDEFOLDERS"
		if not(vecFiles.empty) then AddToFilter flt.file, vecFiles, clickData.func.command, "GLOBALHIDEFILENAME"
		if not(flt.enable) then clickData.func.command.AddLine("Set GLOBALHIDEFILTER on")
		clickData.func.command.Run
	end if

End Function

Function EscapeFilename(strName)
	strName = Replace(strName, "'", "''")
	strName = Replace(strName, "#", "'#")
	strName = Replace(strName, "(", "'(")
	strName = Replace(strName, ")", "')")
	strName = Replace(strName, "~", "'~")
	strName = Replace(strName, "[", "'[")
	strName = Replace(strName, "]", "']")
	EscapeFilename = strName
End Function

Function AddToFilter(strPattern, vecItems, cmd, arg)

	Dim f, existingMatches, setNewMatches
	
	if Left(strPattern, 1) = "(" then strPattern = Right(strPattern, Len(strPattern) - 1)
	if Right(strPattern, 1) = ")" then strPattern = Left(strPattern, Len(strPattern) - 1)
	existingMatches = Split(strPattern, "|")

	Set setNewMatches = DOpus.Create.StringSetI
	for each f in existingMatches
		setNewMatches.insert(f)
	next

	For each f in vecItems
		setNewMatches.insert(EscapeFilename(f))
	Next

	strPattern = "("
	for each f in setNewMatches
		if Len(strPattern) > 1 Then strPattern = strPattern & "|"
		strPattern = strPattern & f
	next
	strPattern = strPattern & ")"

	cmd.AddLine "Set " & arg & " """ & strPattern & """"
	
End Function

THANK YOU! Your script works perfectly :grinning: