`
winhkey
  • 浏览: 4220 次
文章分类
社区版块
存档分类
最新评论

eclipse3.4.2下挂myeclipse7.5

阅读更多

myeclipse7.5里包含了eclipse3.4.2,不过我习惯在eclipse下用link方式挂myeclipse,于是照旧,把common目录下的plugins和features目录copy到自己的插件目录然后用link文件指向它就行了。不过这里包含了eclipse3.4.2自己的plugins和features目录,如何将同名的文件(夹)删除呢? 写个小程序就搞定了。

 

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class DuplicateDelete
{
	public static void main(String[] args)
	{
		check("d:/java/myplugins/myeclipse/eclipse/plugins", "d:/java/eclipse/plugins");
		check("d:/java/myplugins/myeclipse/eclipse/features", "d:/java/eclipse/features");
	}
	
	static void check(String myeclipsePath, String eclipsePath)
	{
		File myeclipse = new File(myeclipsePath);
		File eclipse = new File(eclipsePath);
		
		List<String> files1 = Arrays.asList(myeclipse.list());
		List<String> files2 = Arrays.asList(eclipse.list());
		
		Collections.sort(files1);
		Collections.sort(files2);
		
		int i = 0, j = 0;
		while (true)
		{
			String name1 = files1.get(i);
			String name2 = files2.get(j);
			
			int a = name1.compareTo(name2);
			if (a == 0)
			{
				remove(new File(myeclipsePath + "/" + name2));
				i++;
				j++;
			}
			else if (a < 0)
			{
				i++;
			}
			else
			{
				j++;
			}
			
			if (j == files2.size())
			{
				break;
			}
		}
	}

	static void remove(File directory)
	{
		if (!directory.delete())
		{
			File[] files = directory.listFiles();
			for (int i = 0, n = files.length; i < n; i++)
			{
				if (files[i].isDirectory())
				{
					remove(files[i]);
				}
				else
				{
					files[i].delete();
				}
			}
		}
		directory.delete();
	}
}

 

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics