Compare filenames without extension

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
markcoutinho
Junior Member
Junior Member
Posts: 14
Joined: 2004-11-29, 12:55 UTC

Compare filenames without extension

Post by *markcoutinho »

Hello everyone,

I know the option to compare two directory's (Shift-F2). Works like a charm.

However: I want to compare two dir's which contain a lot of the same filenames, but the extensions are different.
Although these files have different extensions, they should be marked as 'same file'.

Is it possible to do this in TC?
markcoutinho
Junior Member
Junior Member
Posts: 14
Joined: 2004-11-29, 12:55 UTC

Post by *markcoutinho »

Just bumping this question: has anyone a suggestion for my problem?
gdpr deleted 6
Power Member
Power Member
Posts: 872
Joined: 2013-09-04, 14:07 UTC

Post by *gdpr deleted 6 »

Are you talking about "marking the 'same file'" as part of the SHIFT-F2 function?
If so, i am confused because SHIFT-F2 only marks different files, it never marks files it treats as the same.

Or, do you mean you want to have files NOT selected if their file name (without extension) is the same? Then it would still not be very clear what you mean, because SHIFT-F2 also treats files as different (and thus selects them) when these files have the same name but have different file size or file date .
markcoutinho
Junior Member
Junior Member
Posts: 14
Joined: 2004-11-29, 12:55 UTC

Post by *markcoutinho »

Thanks for your answer. It's a pity I obviously didn't make it clear enough what I mean.

Let me give an example.
In directory c:\FirstDir I have these files:
- Mr. Oizo - Flat beat.mp4
- Nits - Sketches of Spain.mp4
- Pebbles - Girlfriend.mp4
- Maywood - Late at night.mp4

In directory c:\SecondDir I have these files
- Mr. Oizo - Flat beat.mpg
- Nits - Sketches of Spain.avi
- Pebbles - Girlfriend.vob

I want TC to compare these two dir's so that I will see this result: "Maywood - Late at night" is missing in c:\SecondDir

(in real life I have some 5,000 files in these directory's - that's why I want to automate this)

Hope this makes it more clear and that you can give me a solution! :-)
User avatar
Stefan2
Power Member
Power Member
Posts: 4155
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Select files with same name but different extension

Post by *Stefan2 »

If you would have only two different extensions,

you could utilize cm_LoadSelectionFromClip=2033;Read file selection from clipboard
(see TOTALCMD.INC)


How to:

1.)
- c:\FirstDir
- select all files
- copy name to clipboard > cm_CopyNamesToClip=2017

2.)
- paste into text editor
- exchange the extension
- select all
- copy to clipboard

3.)
- c:\SecondDir
- utilize cm_LoadSelectionFromClip (select all found files)
- cm_ExchangeSelection=525;Invert selection (show not found files)
- cm_ShowOnlySelected=2023;Hide files which aren't selected



I guess all this could be done by one single VBScript?
Or by the help of "Extended English Menus by petermad"




- - - EDIT, or with a batch :wink:

Code: Select all

@ECHO OFF

REM Batch for TotalCommander, 2014-05-13 by Stefan 
REM select and show files with same name but different extension
REM Call this batch from TC button with %L as parameter


REM == USER SETTINGS ==

rem needed tools
SET nirc=%Commander_Path%\TOOLs\NirSoft\nircmdc.exe
SET sedc=%Commander_Path%\TOOLs\unix\sed.exe

REM Exchange extension:
SET replacefrom=\.txt
SET changeto=\.log



REM == THE CODE don't touch ==

REM %1 comes from TCs, due to the %L parameter
REM exchange the extension:
%sedc% -e s/%replacefrom%/%changeto%/i %1 > %temp%\tcsed.txt

REM Read modfied file content into the clipboard:
rem clipboard [Action] [Parameter] 
%nirc% clipboard readfile "%temp%\tcsed.txt"

REM Activate TC:
rem win [action] [find] [window to find] [Additional Parameters]
%nirc% win activate class TTOTAL_CMD
%nirc% win max class TTOTAL_CMD
REM switch to the other panel:
%nirc% sendkey tab press



REM Execute TC internal commands by sendmessage:
rem win sendmsg [find] [window to find] [Additional Parameters: Msg, wParam, lParam]

REM select files which have name as stored in clipboard:
REM cm_LoadSelectionFromClip 2033
%nirc% win sendmsg class TTOTAL_CMD 1075, 2033, 0

REM invert the selection, select file there name are not in clipboard:
REM cm_ExchangeSelection 525
%nirc% win sendmsg class TTOTAL_CMD 1075, 525, 0

REM Hide not-selected files, show only those files not in clipboard:
REM cm_ShowOnlySelected 2023
rem %nirc% win sendmsg class TTOTAL_CMD 1075, 2023, 0
rem this didn't works?!?!


rem PAUSE


-------------------------------------------


- - - EDIT 2, added some explanation:


This batch needs Nirsoft's NirCmd.exe and one Sed.exe from one of the Unix Tools for Win32.
I have used: GNU sed version 4.0.7, Copyright (C) 2003 Free Software Foundation, Inc.
(The sed part could be done with powershell also. Or both could be done by a Autohotkey script.)

SET nirc=%Commander_Path%\TOOLs\NirSoft\nircmdc.exe
SET sedc=%Commander_Path%\TOOLs\unix\sed.exe

------------------------------

You have to adjust this part according to your needs.
Here I let change the .txt extension to .log by a regular expression syntax:
SET replacefrom=\.txt
SET changeto=\.log


------------------------------

To use this batch, create a button on TC's button bar.
(http://www.ghisler.ch/wiki/index.php/Buttonbar)
Right click the button bar, choose Change... In the open dialog, press F1 key and read.

Button for this batch:
Command: %Commander_Path%\mybatch.cmd
Parameters: %L
Start path:
Icon file: %COMMANDER_PATH%\WCMICONS.DLL,5
Tooltip: Select files same name but different extension in other panel
[X] Run minimized

(Tip: you can also write this into usercmd.ini and assign a hotkey to it)

------------------------------

Usage:
- have folder with reference files open in left pane
- have folder with files to check open in right pane
- click at the TC toolbar button
- done, watch what happens in the right pane

------------------------------

Explanation:
The button parameter %L will create a temporary list of selected files into your temp folder.
The sed.exe will read this list, change the extension and write the changes into temp\tcsed.txt
Nircmd.exe will read this and put it into the clipboard.

Then nircmd will send TC internal commands (see TOTALCMD.INC):
- select files with name as stored in clipboard: cm_LoadSelectionFromClip 2033
- invert the selection, select file there name are not in clipboard: cm_ExchangeSelection 525
- Hide not-selected files, show only those files not in clipboard: cm_ShowOnlySelected 2023 (this particular seems not to work)


.
Last edited by Stefan2 on 2014-05-14, 06:01 UTC, edited 3 times in total.
Kyles
Junior Member
Junior Member
Posts: 22
Joined: 2014-04-01, 01:58 UTC

Post by *Kyles »

markcoutinho wrote: I want TC to compare these two dir's so that I will see this result: "Maywood - Late at night" is missing in c:\SecondDir
1.
Change to c:\SecondDir
Press Ctrl+A (Select all)
Press Ctrl+M (Multi-rename tool)
Set Rename mask: file name = FFFFFF[N]
Set Extension = EEEEEE (Do NOT press Start!)
Press [Edit names...] (The button near the [F2 Load/save settings]), it will edit them with Notepad.
http://imgur.com/nRujiLr

2.
Use Notepad, Search for FFFFFF and Replace with "
Search for EEEEEE and Replace with *"
Press Ctrl+A (Select all)
Press Ctrl+C (Copy to clipboard)
http://imgur.com/5xnXec8

3.
Change to c:\FirstDir
Command line execute: cm_LoadSelectionFromClip,cm_ExchangeSelection
If you need to copy the above commands to clipboard, you will need back to Notepad to copy files name again.
http://imgur.com/W8Zpiuz
markcoutinho
Junior Member
Junior Member
Posts: 14
Joined: 2004-11-29, 12:55 UTC

Post by *markcoutinho »

Thanks Stefan2 and Kyles for these answers. I gave it a first go with Kyles' directions but the last step didn't work out the way you showed, so tonight or tomorrow I'll give it another go (I'm at the office right now so I haven't much time).
Thanks so far - your step by step instruction is amazing!
Kyles
Junior Member
Junior Member
Posts: 22
Joined: 2014-04-01, 01:58 UTC

Post by *Kyles »

Full step by step:

TC Right panel: c:\SecondDir
TC Left panel: c:\FirstDir

1.
-Click Right panel
-Press Ctrl+A
-Press Ctrl+M
-Set Rename mask: file name = FFFFFF[N]
-Set Extension = EEEEEE
-Press [Edit names...]

2.
-Press Ctrl+H
-Set Search for = FFFFFF
-Set Replace with = "
-Press Alt+A
-Set Search for = EEEEEE
-Set Replace with = *"
-Press Alt+A
-Press ESC
-Press Ctrl+A
-Press Ctrl+C

3.
-Back to TC
-Click Cancel
-Click Close
-Click Left panel
-Press Ctrl+Down
-Command line fill in: cm_LoadSelectionFromClip,cm_ExchangeSelection
(This time, please do NOT use Copy & Paste above commands)
-Press Enter
markcoutinho
Junior Member
Junior Member
Posts: 14
Joined: 2004-11-29, 12:55 UTC

Post by *markcoutinho »

Utterly brilliant, Kyles. As well the solution in itself as your superbe step-by-step explanation.

Stefan: your batch looks great too. But I don't quite understand how to use it. Do I have to tell the batch somewhere where the directory's are that need to be compared?
Do I start the batch from the Windows Command prompt or from somewhere in TC?

For future use I'd love to see how/what with this batch.

Again: many thanks to both of you! Saved me a lot of time (I found 170 missing files out of 4,500 files)
User avatar
Stefan2
Power Member
Power Member
Posts: 4155
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

markcoutinho wrote:Stefan: your batch ... I don't quite understand how to use it.
This is common knowledge and written many times in forum and wiki, so I let it out :wink:

But I have once again added it above for more comfortable reference.


Have fun.
Post Reply