Match file pairs with file extension

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
maglet
Junior Member
Junior Member
Posts: 9
Joined: 2010-05-01, 00:46 UTC

Match file pairs with file extension

Post by *maglet »

I have a folder with .dng files and .jpg files.
They are the same files but with different file formats.

After I've deleted some of the jpg-files - I'd also like to remove the dng files.

I end up having a folder like this:

File1.dng
File1.jpg
File2.dng
File2.jpg (deleted)
File3.dng
File3.jpg
File4.dng
File4.jpg (deleted)

I then like to remove the corresponding dng-files.

How do I get TC to remove the File4.dng and File2.dng in the example above?
User avatar
Stefan2
Power Member
Power Member
Posts: 4161
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: Match file pairs with file extension

Post by *Stefan2 »

maglet wrote: 2020-05-03, 15:29 UTC I have a folder with .dng files and .jpg files.
They are the same files but with different file formats.

After I've deleted some of the jpg-files - I'd also like to remove the dng files.

I end up having a folder like this:

File1.dng
File1.jpg
File2.dng
File2.jpg (deleted)
File3.dng
File3.jpg
File4.dng
File4.jpg (deleted)

I then like to remove the corresponding dng-files.

How do I get TC to remove the File4.dng and File2.dng in the example above?

PowerShell
dir *.dng|%{$B=$_.BaseName; IF(-Not(Test-Path "$B.jpg")){"$B.JPG not found, delete $($_.Name)"}}
File2.JPG not found, delete File2.dng
File4.JPG not found, delete File4.dng

Add a function to actual delete the files without an buddy instead of just put out the text string.





Or copy the wanted files names to clipboard, next use "Get Selection from Clipboard"
and you have the files selected to work on, for example use "Show only Selected Files".

To have all available internal commands in menu I can recommend
"Extended English Menus for Total Commander" (by petermad)
>> http://www.totalcmd.net/authors/1223914.html


For to add to the clipboard, utilize DOS-Command CLIP (problem with umlauts):
$OUT='';dir *.dng|%{$B=$_.BaseName; IF(-Not(Test-Path "$B.jpg")){"$B.JPG not found, delete $($_.Name)";$OUT+=$($_.Name)+"`r`n"}}; $OUT|clip

Or utilize an commandlet if available (needs PoSh v4 or v5? or an own created commandlet):
$OUT='';dir *.dng|%{$B=$_.BaseName; IF(-Not(Test-Path "$B.jpg")){"$B.JPG not found, delete $($_.Name)";$OUT+=$($_.Name)+"`r`n"}}; $OUT|Set-Clipboard






 
User avatar
petermad
Power Member
Power Member
Posts: 14829
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Match file pairs with file extension

Post by *petermad »

2maglet
1. Press Num+ (or Mark -> Select Group)
2. Enter: *.jpg > *.dng
3. Press OK

Now all matching jpg/dng pairs (File1.* and File3.*) are marked

4. Press Num * (or Mark -> Invert Selection)

Now File4.dng and File2.dng should be marked.

Help wrote:Selecting files
.
.
.You can also select related files. For example, you would want to select all RAW image files (.cr2), but only if there is a jpg file in the same directory. This can be done with the following selection string:
*.jpg>*.cr2
This also supports more complex naming schemes. For example, if the jpg file is named IMG_1057.JPG and the raw file CRW_1057.CR2, the selection string would have to be:
*.jpg>crw*.cr2
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Stefan2
Power Member
Power Member
Posts: 4161
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Match file pairs with file extension

Post by *Stefan2 »

petermad wrote: 2020-05-03, 23:30 UTC...
....
Now File4.dng and File2.dng should be marked.
....

...and so are any other unrelated files too.



You just have to know and to take care.


 
maglet
Junior Member
Junior Member
Posts: 9
Joined: 2010-05-01, 00:46 UTC

Re: Match file pairs with file extension

Post by *maglet »

Thanks for all replies! All methods worked out fine.

I've been using TC as a registered user for many years - and still missing the help section pointing out exactly what I want do do :cry:

TC is amazing!
User avatar
petermad
Power Member
Power Member
Posts: 14829
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Match file pairs with file extension

Post by *petermad »

2maglet
and still missing the help section pointing out exactly what I want do do
Maybe this is what you want:
  1. Open Help
  2. Click on the Index tab
  3. Type: Selecting files
  4. Double click on "Selecting files" in the list
  5. Click on "Selecting files" in the bottom of the main window.
It would have been a great benefit if a press on F1 when in the "Expand selection" dialog (Num+), would show shis help.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply