osc用svn提交包含空目录解决办法

在osc用svn提交项目代码的时候,发现项目包含空目录时会提交失败。
Error: Commit failed (details follow):  
Error: svn: E200015: Empty directories is not supported: /lib 


在开源社区问答处看到有人建议在空文件夹下建一个空的文件.keep。根据此方法写了个自动处理的方法。

功能:遍历jar所在目录的所有文件夹,对空的文件夹创建.keep文件。

使用前提:要装jvm

使用方法:把 createKeep.jar放在要上传项目的目录下,上传前双击运行即可(本人只在win7上测试)。


CreateKeep.java

import java.io.File;
import java.io.IOException;

public class CreateKeep {

	public static final String packageFile = ".keep";

	public static void main(String[] args) {
		String path = getRealPath();
		File file = new File(path);
		try {
			traversalAllFolder(file);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 遍历当前文件夹下的所有文件夹,对空的文件夹创建.keep文件
	 * 
	 * @param dir
	 * @throws Exception
	 */
	final static void traversalAllFolder(File dir) throws Exception {
		File[] fs = dir.listFiles();
		int fsLength = fs.length;
		if (fsLength == 0) {
			createFile(dir.getAbsolutePath());
		} else {
			for (int i = 0; i < fsLength; i++) {
				if (fs[i].isDirectory()) {
					try {
						traversalAllFolder(fs[i]);
					} catch (Exception e) {
					}
				}
			}
		}
	}

	/**
	 * 创建.keep文件
	 * 
	 * @param folderPath
	 *            路径名
	 */
	public static void createFile(String folderPath) {
		String fileName = folderPath + "/" + packageFile;
		File file = new File(fileName);
		try {
			file.createNewFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取当前jar包所在路径
	 * 
	 * @return
	 */
	public static String getRealPath() {
		String realPath = CreateKeep.class.getClassLoader().getResource("")
				.getFile();
		java.io.File file = new java.io.File(realPath);
		realPath = file.getAbsolutePath();
		try {
			realPath = java.net.URLDecoder.decode(realPath, "utf-8");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return realPath;
	}

}

下载地址:createKeep.zip

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值