Compare Panes

Discuss and share scripts and script files...
Post Reply
jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Compare Panes

Post by jacky »

Because procrastination can be useful to some... :)

I don't use DP myself, and when I need to do some folder comparison I use a dedicated tool to do so, but if you want a simple basic "compare pane" feature, here's a little script that you might find useful.

How it works? You have two folders in your two panes, and start the script. A window will show the results, listing all items and showing which are the same on both panes, which have different sizes, which have different modified dates, and which are not found on one pane or the other.
After you closed that window, you'll be asked if you want to hide from both panes items that are the same (using a VF). Note that because of this feature, you cannot use this script with a VF on either pane - they are automatically removed.

Of course you are free to change the script to best suit your needs, and if you're not much of a scripter there's a couple of simple "options" you can still change : the first two lines define how items are compared.

By default, the script checks the sizes & modified dates of items. Only if both items have the same size & modified date will they be marked as the same. If you only want to compare sizes, or modified dates, or none (and have items be "the same" if they exists on both pane, easy to find out which items are on only one of the panes) simply change $check_size and/or $check_modified to FALSE.

It should work as expected, but I can't be responsible for anything ;)

Code: Select all

"Compare"
	// config
	$check_size = TRUE;
	$check_modified = TRUE;
	// eo.config
	$report = "{Name}|{Size RAW}|{Size B}|{Modified ddmmyyyyhhnnss}|{Modified}<crlf>";
	// gather info from pane 1
	focus p1;
	filter;
	$list1 = report($report);
	$count1 = <get CountItems>;
	// gather info from pane 2
	focus p2;
	filter;
	$list2 = report($report);
	$count2 = <get CountItems>;
	
	// ensure we got something to do
	if (0 == $count1 || 0 == $count2)
	{
		end 1, 'There must be at least one item in each pane.', 1;
	}
	
	// determine which list is smaller/will go faster
	if ($count1 > $count2)
	{
		$ref = 2;
		$cmp = 1;
		$list = $list2;
		$list2 = $list1;
	}
	else
	{
		$ref = 1;
		$cmp = 2;
		$list = $list1;
	}
	
	// init: list of items same on both panes (to be excluded via VF)
	$vf = '';
	// init: results report
	$report = '';
	
	// loop through list
	while ('' != $list)
	{
		// extract first line of info from list
		$p = strpos($list, <crlf>);
		$line = substr($list, 0, $p);
		$list = substr($list, $p + 2);
		// get info
		$name = gettoken($line, 1, '|');
		$size = gettoken($line, 2, '|');
		$size_nice = gettoken($line, 3, '|');
		$modified = gettoken($line, 4, '|');
		$modified_nice = gettoken($line, 5, '|');
		// now search for that file on other list
		$p = strpos("<crlf>$list2", "<crlf>$name|");
		if (-1 == $p)
		{
			// file not found
			$report = "$report<tr style=""color: red;""><td>$name</td><td>" . ((1 == $cmp) ? "NOT FOUND" : "-") . "</td><td>" . ((1 == $cmp) ? "-" : "NOT FOUND") . "</td></tr><crlf>";
		}
		else
		{
			// file found, extract line of info for that item
			$p2 = strpos($list2, <crlf>, $p + 2);
			$line = substr($list2, $p, $p2 - $p);
			$list2 = substr($list2, 0, $p) . substr($list2, $p2 + 2);
			// get info
			$size2 = gettoken($line, 2, '|');
			$size2_nice = gettoken($line, 3, '|');
			$modified2 = gettoken($line, 4, '|');
			$modified2_nice = gettoken($line, 5, '|');
			// checking
			$same = TRUE;
			// compare size?
			if ($check_size)
			{
				if ($size != $size2)
				{
					$same = FALSE;
					// size differ
					$report = "$report<tr style=""color: orange;""><td>$name</td><td>" . ((1 == $ref) ? $size_nice : $size2_nice) . "</td><td>" . ((1 == $ref) ? $size2_nice : $size_nice) . "</td></tr><crlf>";
				}
			}
			// compare modified?
			if ($same && $check_modified)
			{
				if ($modified != $modified2)
				{
					$same = FALSE;
					// modified differ
					$report = "$report<tr style=""color: violet;""><td>$name</td><td>" . ((1 == $ref) ? $modified_nice : $modified2_nice) . "</td><td>" . ((1 == $ref) ? $modified2_nice : $modified_nice) . "</td></tr><crlf>";
				}
			}
			// same?
			if ($same)
			{
				// same name, size and modified
				$report = "$report<tr style=""color: gray;""><td>$name</td><td>-</td><td>-</td></tr><crlf>";
				// add to exclusion VF
				$vf = "$vf|$name";
			}
		}
	}
	
	// loop through the remaining list2 (i.e. items in pane 2 not in pane 1)
	while ('' != $list2)
	{
		// extract first line of info from list
		$p = strpos($list2, <crlf>);
		$line = substr($list2, 0, $p);
		$list2 = substr($list2, $p + 2);
		// get info
		$name = gettoken($line, 1, '|');
		// file not in pane 1
		$report = "$report<tr style=""color: red;""><td>$name</td><td>" . ((1 == $ref) ? "NOT FOUND" : "&nbsp;") . "</td><td>" . ((1 == $ref) ? "-" : "NOT FOUND") . "</td></tr><crlf>";
	}
	
	// show results
	html("Items said to be the same if they had the same names" . (($check_size) ? ", sizes" : "") . (($check_modified) ? ", modified dates" : "") . ".<br>Legend:<br><span style=""color: red;"">Missing from one pane</span>" . (($check_size) ? "<br><span style=""color: orange;"">Sizes differ</span>" : "") . (($check_modified) ? "<br><span style=""color: violet;"">Modified dates differ</span>" : "") . "<br><span style=""color: gray;"">Items are the same</span><br><br><table border=1><tr><td>Name</td><td>Pane 1</td><td>Pane 2</td></tr>$report</table>");
	
	// set up the VF, if there's need for one
	if ('' != $vf)
	{
		if (confirm('Do you want to hide same items on both panes using a VF ?<br><br>OK will hide the following items on both panes :<br>' . replace($vf, '|', '<br>- ')))
		{
			$vf = '!' . replace(replace(substr($vf, 1),'[','[[]'),'#','[#]');
			focus p1;
			filter $vf;
			focus p2;
			filter $vf;
		}
	}
Proud XYplorer Fanatic

Post Reply