How to select such files?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
netsonicyxf
Junior Member
Junior Member
Posts: 6
Joined: 2021-09-01, 01:52 UTC

How to select such files?

Post by *netsonicyxf »

I have some files that were converted to new files, whose name is in "orignal file name_h265" format and the extension are converted to mp4, e.g.

1.ts -> 1_h265.mp4
3.mp4 -> 3_h265.mp4

The files list look like this:
1 2.ts
1 2_h265.mp4
2.mp4
3.mp4
3_h265.mp4
4.MP4

I want to select these files:
1 2.ts
1 2_h265.mp4
3.mp4
3_h265.mp4
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: How to select such files?

Post by *MVV »

I'm afraid that currently there is no way to make such selection with TC only.

It would be perhaps nice to be able to select files using two regex expressions where first one defines matching group of characters and second one uses it, e.g. <(.*)_h265\.mp4 > $1\..*, but it is just an idea and it doesn't work now.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: How to select such files?

Post by *MVV »

You can use however following batch+powershell file:

Code: Select all

@echo off
set "ARG_0=%~dpnx0"
set "ARG_1=%~dp0"
set "ARG_2=(.*)_h265.mp4"
set "ARG_3=$1.*"
powershell.exe -NoProfile "iex (([IO.File]::ReadAllText($Env:ARG_0)) -replace '^(.*\n)*?.*<::::>.*\n', '')" & goto :EOF


$sourceDir = $Env:ARG_1;
$pattern = $Env:ARG_2;
$replacement = $Env:ARG_3;

$selectedFiles = @();
foreach ($file in (ls "$sourceDir\*")) {
	if ($file.Name -match $pattern) {
		$selectedFiles += $file.Name;
		$selectedFiles += $file.Name -replace $pattern, $replacement;
	}
}

if ($selectedFiles) {
	'Selection:';
	$selectedFiles;

	Add-Type -AssemblyName 'System.Windows.Forms';
	[System.Windows.Forms.Clipboard]::SetText($selectedFiles -join "`n");
}
else {
	'No files found';
}
Just save it as e.g. selectMedia.bat somewhere, add to TC buttonbar and don't forget to clear Start path field in button properties to make it working with current directory!
Another button you will need is with cm_LoadSelectionFromClip command.

So you have to open the folder with media files, press first button for calculating selection and putting it to clipboard and then press second button for selecting files according to the selection.
netsonicyxf
Junior Member
Junior Member
Posts: 6
Joined: 2021-09-01, 01:52 UTC

Re: How to select such files?

Post by *netsonicyxf »

Thank you for the solution.

Finally I use TC + text editor to do it.
Filter file names by "_h265", copy the name to text editor, delete "_h265" and add "* and *" at the start and end of the file name, e.g.

"*1 2*"

then select files using this pattern
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: How to select such files?

Post by *MVV »

For single-time case text editor may be useful, yes. But such a script may help if you need to do such selection often or with different rules. :)
Post Reply