jEdit Community - Resources for users of the jEdit Text Editor
diff between folders
Submitted by bambule on Tuesday, 28 November, 2006 - 21:37
Hi all,

the jEdit has the nice JDiff Plugin. But sometimes I need to diff two folders. I would be nice to have a Plugin to select two folders and the different files will be shown in JDiff. So the most difficult things are done and there is just an interface needed between JDiff and "FolderDiff".
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
How about a Macro
by elberry on Thu, 30/11/2006 - 17:35
You don't really need a plugin for this, you can do this with a macro.
[code]
public String printDirectoryContents(File directory) {
	StringBuffer directoryContents = new StringBuffer();
	String[] fileNameArray = directory.list();
	for(String fileName : fileNameArray) {
		directoryContents.append(fileName).append("\n");
	}
	return directoryContents.toString();
}
String tempFileBasePath = jEdit.getSettingsDirectory() + "/dirdiff/";
File directory1 = null;
File directory2 = null;
JFileChooser fileChooser = new JFileChooser(buffer.getDirectory());
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setDialogTitle("Choose First Directory");
int returnValue = fileChooser.showOpenDialog(view);
if(returnValue == JFileChooser.APPROVE_OPTION) {
	directory1 = fileChooser.getSelectedFile();
	fileChooser.setDialogTitle("Choose Second Directory");
	returnValue = fileChooser.showOpenDialog(view);
	if(returnValue == JFileChooser.APPROVE_OPTION) {
		directory2 = fileChooser.getSelectedFile();
	}
}
Buffer file1Buffer = jEdit.openFile(view, tempFileBasePath + directory1.getName());
Buffer file2Buffer = jEdit.openFile(view, tempFileBasePath + directory2.getName());
file2Buffer.insert(0, printDirectoryContents(directory2));
file1Buffer.insert(0, printDirectoryContents(directory1));
view.goToBuffer(file1Buffer);
view.splitVertically();
view.goToBuffer(file2Buffer);
EditPlugin sqlPlugin = jEdit.getPlugin("jdiff.JDiffPlugin", true);
PluginJAR sqlPluginJar = sqlPlugin.getPluginJAR();
ActionSet sqlPluginActionSet = sqlPluginJar.getActionSet();
sqlPluginActionSet.getAction("toggle-dual-diff").invoke(view);
[/code]
Learn from the past. Live in the present. Plan for the future.
 
does not work for comparing f
by poleta33 on Fri, 22/12/2006 - 09:14
does not work for comparing folders with same name...
 
Updated & Fixed
by elberry on Fri, 22/12/2006 - 16:19
I modified this a little while ago, here's the one I'm currently using. It fixes the issue where the directory names are the same, and adds a few other options for comparing the modified date, size of files and recursively traversing the directories. Hope this helps.
[code]
import java.text.*;

SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM dd, yy HH:mm ");

public boolean ignoreFile(File file) {
	boolean ignore = false;
	String fileName = file.getName();

	// add stuff here to ignore more files/folders
	if(fileName.equals("CVS") || fileName.equals(".DS_Store")) {
		ignore = true;
	}

	return ignore;
}

public String printDirectoryContents(StringBuffer tabBuffer, File directory) {

	// set to true to show modified date
	boolean compareModifiedDate = false;

	// set to true to show file sizes
	boolean compareSize = false;

	// set to true to show contents of sub folders too
	boolean recursive = true;

	StringBuffer directories = new StringBuffer();
	StringBuffer files = new StringBuffer();
	File[] fileArray = directory.listFiles();
	for(File file : fileArray) {
		if(!ignoreFile(file)) {
			if(file.isDirectory()) {
				directories.append(tabBuffer);
				if(compareModifiedDate) {
					directories.append(dateFormatter.format(new Date(file.lastModified())));
				}
				directories.append(file.getName());
				directories.append("\n");
				if(recursive) {
					StringBuffer newTabBuffer = new StringBuffer(tabBuffer);
					newTabBuffer.append("\t");
					directories.append(printDirectoryContents(newTabBuffer, file));
				}
			} else {
				files.append(tabBuffer);
				if(compareModifiedDate) {
					files.append(dateFormatter.format(new Date(file.lastModified())));
				}
				if(compareSize) {
					files.append(" " + file.length());
					files.append(" ");
				}
				files.append(file.getName());
				files.append("\n");
			}
		}
	}
	directories.append(files);
	return directories.toString();
}
String tempFileBasePath = jEdit.getSettingsDirectory() + "/dirdiff/";
File directory1 = null;
File directory2 = null;
JFileChooser fileChooser = new JFileChooser(buffer.getDirectory());
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setDialogTitle("Choose First Directory");
int returnValue = fileChooser.showOpenDialog(view);
if(returnValue == JFileChooser.APPROVE_OPTION) {
	directory1 = fileChooser.getSelectedFile();
	fileChooser.setDialogTitle("Choose Second Directory");
	returnValue = fileChooser.showOpenDialog(view);
	if(returnValue == JFileChooser.APPROVE_OPTION) {
		directory2 = fileChooser.getSelectedFile();
	}
}
Buffer file1Buffer = jEdit.openFile(view, tempFileBasePath + "directory1");
Buffer file2Buffer = jEdit.openFile(view, tempFileBasePath + "directory2");
file2Buffer.insert(0, printDirectoryContents(new StringBuffer(), directory2));
file2Buffer.insert(0, directory2.getPath() + "\n\n");
file1Buffer.insert(0, printDirectoryContents(new StringBuffer(), directory1));
file1Buffer.insert(0, directory1.getPath() + "\n\n");
view.goToBuffer(file1Buffer);
view.splitVertically();
view.goToBuffer(file2Buffer);
EditPlugin sqlPlugin = jEdit.getPlugin("jdiff.JDiffPlugin", true);
PluginJAR sqlPluginJar = sqlPlugin.getPluginJAR();
ActionSet sqlPluginActionSet = sqlPluginJar.getActionSet();
sqlPluginActionSet.getAction("toggle-dual-diff").invoke(view);

[/code]
Learn from the past. Live in the present. Plan for the future.
User login
Browse archives
« March 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82338
Context Free Art (*.cfdg)   0.31   46043
JBuilder scheme   .001   18487
BBEdit scheme   1.0   18107
ColdFusion scheme   1.0   18015
R Edit Mode - extensive version   0.1   17461
Advanced HTML edit mode   1.0   16194
Matlab Edit Mode   1.0   16057
jEdit XP icons   1.0   15220
XP icons for jEdit   1.1   14281