Author Topic: File compare by content  (Read 21003 times)

Suncatcher

  • Active Member
  • ***
  • Posts: 104
    • View Profile
File compare by content
« on: August 08, 2017, 23:46:20 »
Hi,
five years ago you said you gonna implement file compare by checksum. IS this featue still on the way? How can I compare two folders to find identical files disregard of their names?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4490
    • View Profile
    • Multi Commander
Re: File compare by content
« Reply #1 on: August 09, 2017, 15:17:19 »
You can't do complete folders, but files, 
Menu > Tools > File Checksum > Compare content of two files.

But you can script it.. You can get the checksum from script
and you can call it by script to get checksum with ChkSum_Calculate(..)

I do have it still on my list, But I'm very busy do not have so much free time to spent on MC would be required to fixed everything, and there been a lot of other features that been selected as more important to add.


Suncatcher

  • Active Member
  • ***
  • Posts: 104
    • View Profile
Re: File compare by content
« Reply #2 on: August 09, 2017, 15:44:36 »
Okay, will wait.

Srutinrun

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: File compare by content
« Reply #3 on: November 13, 2017, 09:21:45 »
It is a very good comparison. The picture is really clear.

pncdaspropagandas

  • Contributor
  • Active Member
  • *****
  • Posts: 93
    • View Profile
Re: File compare by content
« Reply #4 on: December 06, 2017, 11:46:29 »
I also compare a lot of files and folders. To fulfill my needs, while MC don't do it natively, I created scripts to compare 2 files:

2 files on same panel:
Code: [Select]
import("MFTools-sfv");

// Array com os arquivos selecionados
@var $arr_selected_files[] = GetSelectedPaths();

// Array com o checksum dos arquivos
@var $arr_checksum[];

// Array que controla quais arquivos/checksums já foram analizados no agrupamento
@var $arr_checksum_match[];

// Os arquivos acima tem o mesmo tamanho, o abaixo é maior por conta das linhas em branco que separam os grupos

// Array que recebe os arquivos agrupados por checksum e gera o arquivo log
@var $arr_checksum_log_file[];

@var $base_checksum;
@var $arr_log_differences = { 'No', 'Yes' };
@var $log_differences;
@var $log_file = GetSourcePath() ^ '_MC_file_differences.log';
@var $log_file_content;

// result == 0 same hash; 1 == different hash
@var $result = 0;
@var $cs;
@var $csn;
@var $n;
@var $i;
@var $c;
@var $j;

if( arrayCount($arr_selected_files) == 0)
{
MessageBox('Compare content of files', 'Select 2 or more files.', 0);
}
else if( arrayCount($arr_selected_files) == 1)
{
MessageBox('Compare content of files', 'Select 2 or more files.', 0);
}
else
{
// Calculate checksums
for( $n = 0; $n < arrayCount($arr_selected_files); $n++ )
{
$cs = ChkSum_Calculate($arr_selected_files[$n], 2);
arrayAdd($arr_checksum, $cs);
}

// All checksums are equal?
$cs = $arr_checksum[0];
for( $n=1; $n < arrayCount($arr_selected_files); $n++ )
{
$csn = $arr_checksum[$n];
if( !(StrIsEqual($cs, $csn)) )
{
$result = 1;

if( arrayCount($arr_selected_files) > 2)
{
// User input
$log_differences = AskOption( 'Log file differences to _file_differences.log?', $arr_log_differences, 0 );

if( $log_differences )
{
// Delete previous log
if ( FileExists($log_file) )
{
@var $options[] = {"NODIALOG", "NOPROGRESS"};
DeleteFile($log_file, $options);
if ( FileExists($log_file) )
{
MessageBox('Compare content of files', 'Could not delete "_file_differences.log".', 0);
break;
}
}

// Log file initialization
arrayAdd($arr_checksum_log_file, "The following files are grouped by checksum (SHA1):");
arrayAdd($arr_checksum_log_file, "");

// Creates a new array to control wich files were already matched and group them
for( $n=0; $n < arrayCount($arr_checksum); $n++ )
{
arrayAdd($arr_checksum_match, 0);
}

// Group files by checksum
// for each file/checksum (as base)
for( $n=0; $n < arrayCount($arr_selected_files) - 1; $n++ )
{
// base not checked/grouped/matched yet?
$c = $arr_checksum_match[$n];
if( $c == 0 )
{
$base_checksum = $arr_checksum[$n];
$arr_checksum_match[$n] = 1;
arrayAdd($arr_checksum_log_file, $arr_selected_files[$n]);
// for each following file/checksum
for( $j = $n + 1; $j < arrayCount($arr_selected_files); $j++ )
{
$cs = $arr_checksum[$j];
if( StrIsEqual($base_checksum, $cs) )
{
$arr_checksum_match[$j] = 1;
arrayAdd($arr_checksum_log_file, $arr_selected_files[$j]);
}
}

// Add a break to the log file
arrayAdd($arr_checksum_log_file, "");
}
}

// Write log file
$log_file_content = StrLinesArray2String($arr_checksum_log_file);
SaveStringToFile( $log_file, $log_file_content, 1 );
}

}

MessageBox('Compare content of files', 'Files are different.', 0);
break;
}
}

if( $result == 0)
{
MessageBox('Compare content of files', 'All files are equal.', 0);
}
}

2 files on different panels:
Internal Command - File Checksum Verifier - Compare contents od two files

2 folders - using WinMerge:
Custom Command
MC.Run CMD='"${mcpath}Tools\\WinMerge\\WinMergeU.exe"' ARG='/s /r /e /x /u /maximize "${sourcepath}" "${targetpath}"'

2 folders - using FreeFileSync:
Code: [Select]
@var $mcinstallpath = GetTagValue("${mcinstallpath}");

@var $arr_ffs_paths[];
arrayAdd( $arr_ffs_paths, "C:\\Program Files\\FreeFileSync\\FreeFileSync.exe" );
arrayAdd( $arr_ffs_paths, "C:\\Program Files (x86)\\FreeFileSync\\FreeFileSync.exe" );

@var $ffs_path_mc_tools;
@var $ffs_path = "";
@var $path;

@var $leftpath = GetTagValue("${leftpath}");
@var $rightpath = GetTagValue("${rightpath}");

@var $n;

// First try to use ffs at Program Files
for( $n=0; $n<arrayCount($arr_ffs_paths); $n++ )
{
$path = $arr_ffs_paths[$n];
if( FileExists($path) == 1 )
{
$ffs_path = $path;
break;
}
}
// If not found then try to use mcinstalldir\Tools\FreeFileSync
if( StrIsEqual($ffs_path, "") )
{
$ffs_path_mc_tools = $mcinstallpath ^ "Tools\\FreeFileSync\\FreeFileSync.exe";
if( FileExists($ffs_path_mc_tools) )
{
$ffs_path = $ffs_path_mc_tools;
}
else
{
MessageBox('ffs', 'ffs not found at "Program Files", neither at Tools dir "' + $ffs_path_mc_tools + '"', 0);
break;
}
}

LogAppInfo('Using: '+ $ffs_path);

//LogAppInfo('"' + $ffs_path + '" -leftdir "' + $leftpath + '" -rightdir "' + $rightpath + '"');
MC.Run CMD={$ffs_path} ARG={'"' + $mcinstallpath ^ 'Tools\\FreeFileSync\\Profiles\\Compare_Time_Size.ffs_gui" -leftdir "' + $leftpath + '" -rightdir "' + $rightpath + '"'}