Skip to content

Instantly share code, notes, and snippets.

@lyaotian
Created September 30, 2013 11:59
Show Gist options
  • Select an option

  • Save lyaotian/6762751 to your computer and use it in GitHub Desktop.

Select an option

Save lyaotian/6762751 to your computer and use it in GitHub Desktop.
Delete all .svn files which inside the svn project directory.
package com.lyaotian.test;
import java.io.File;
import java.io.IOException;
/**
* User: Yaotian Leung
* Date: 9/30/13
* Time: 4:53 PM
*/
public class Main {
public static final void main(String[] args) throws IOException {
if (args == null || args.length != 1) {
System.out.println("Usage: Main path\nexample: Main \"C:\\dir1\\dir2\"");
return;
}
String path = args[0];
System.out.println("search in " + path);
search(path);
}
static int count = 0;
private static void search(String path) throws IOException {
File file = new File(path);
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
String SVN = ".svn";
for (File f : files) {
String dirName = f.getName();
if (SVN.equals(dirName)) {
System.out.println(f.getAbsolutePath() + "; count=" + (count++));
deleteFile(f);
}
if (f.isDirectory()) {
search(f.getAbsolutePath());
}
}
}
}
}
private static void deleteFile(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
if (files.length <= 0) {
file.delete();
System.out.println("File is deleted : "
+ file.getAbsolutePath());
} else {
for (File f : files) {
deleteFile(f);
}
files = file.listFiles();
if (files.length == 0) {
file.delete();
System.out.println("Directory is deleted : "
+ file.getAbsolutePath());
}
}
}
} else {
boolean isDelete = file.delete();
System.out.println("delete file: " + file.getAbsolutePath() + ":" + isDelete);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment