Select files with same extension as currently selected

Hi, just saw a similar post that made me think of something I'd like to do... bind a hotkey to a function that will take the selected filetype, and select all other files with the same extension. Can this be done? Haven't seen how to process the selected files extension... setup a filter maybe?

You have to write a little VBScript to get just the file extension, but it does work fine (provided your Anti-Virus will allow scripts like this to run).

Save this into a file called SelectByExt.vbs:

[code]option explicit

Dim fs,shell,args,filename,ext

Set args = WScript.Arguments

if args.Count = 1 then

filename = args.item(0)

Set fs = CreateObject("Scripting.FileSystemObject")

ext = fs.GetExtensionName(filename)

if (ext <> "") then

	Set shell = CreateObject("WScript.Shell")
	shell.Run("""C:\Program Files\GPSoftware\Directory Opus\DOpusRT.exe"" /CMD Select *." & ext)

end if

end if[/code]Then make a button in Opus which runs it giving the first selected filename as an argument:

"C:\SelectByExtension.vbs" {file$}And that should do it. Of course, if you haven't installed Opus in the standard location you'll need to edit the script slightly.

If you have more than one file selected the script will be run for each file with the result that you'll do some redundant selecting (not the end of the world) and you can also select more than one extension at once (could be useful; could also be annoying).

You could change the Select command inside the script to only act on Files if you want to avoid selecting directories with the matched extension. I left that out to keep things simple.

You could also improve it so that you can give it all selected filenames at once and it loops through them, avoiding selections of extensions it's already selected.

Or if you happen to be using Windows NT or higher, you could do it with the following button and simple batch file:

Name=Select File Types
Tooltip=Selects all files of the type currently selected
Func1=runmode hide
Func2=cd C:\Mine\cmd
Func3="C:\Mine\cmd\Select File Types.bat" {f}

Note if you copy and paste the above button to a toolbar, you'll probably have to manually add the {f} control code at the very end of it as DOpus seems to strip that out when I copy and paste the button. If that {f} is not added, the button selects all files in the active lister instead of the types you want.

The Batch File named "C:\Mine\cmd\Select File Types.bat" is a one liner and shown below:

start "" dopusrt.exe /CMD Select *%~x1

This will select not just one file type if you only have one type selected, it will select more than one type if you have more than one file type selected. For example, if you have a .TXT file and a .HTML file selected when you run this button/batch file, it will select all the other .TXT and .HTML files in the active lister.

Anyone who tries this will need to change the name and path to the batch file to the name and path of your batch file.


Hey there John, thanks a bunch... I was hoping there was a way to do it fully in Opus without having to rely on external files, but no big... and you saved me the effort of having to revisit NT command line variable expression syntax to do it :slight_smile:.

So, I went with the batch file method since I didn't want to have to install any additional VB runtime support for the vb script method. I bound a hotkey to it rather than setting up a button and also did away with the change directory (cd) call and the path to the batch file and just stuck the batch script in the first folder in my search path.

It works as intended... and I'm especially digging the benefit of it grabbing all file types if different types are selected. Well done, and thanks again.

Don't know about lesser versions of Windows but XP, at least, has WScript built-in.

The batch file is a bit simpler though; just wanted to point out that using VBScript shouldn't be overlooked for other reasons/situations.

Hi Nudel, sorry but I just realized you provided the VB script reply. Could have sworn John did both... woopsy. And as you said, XP provides native Wscript support; so thanks again for the time taken to write up that VB code... I'll put it in a pocket for future reference.

It's all good. I'd probably use John's batch file over the script, since it's simpler. I didn't remember that batch files could strip filenames down to extensions when I wrote the VBScript. :slight_smile:

Nice to have two ways to do something instead of none.