Created
September 30, 2013 11:59
-
-
Save lyaotian/6762751 to your computer and use it in GitHub Desktop.
Delete all .svn files which inside the svn project directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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