Cleanup .svn folders Java

I just did quick and simple java code for delete .svn folders and its sub files in the eclipse project directory.

You can feel free to copy, paste and modify the code.

import java.io.File;

public class CleanUp {
	public static void main(String args[]){
		String path = "C:\\cleanup\\";
		File root = new File(path);
		traverseFile(root);
	}

	public static void traverseFile(File path){
		if(path.exists()){
			if(path.isDirectory()){
				if(path.getName().equals(".svn")){
					deleteFiles(path);
				}else{
					File [] subFiles = path.listFiles();
					for(int i=0; i < subFiles.length; i++){
						traverseFile(subFiles[i]);
					}
				}
			}
		}
	}

	public static boolean deleteFiles(File path){
		if(path.exists() && path.isDirectory()){
			File [] subFiles = path.listFiles();
			for(int i=0; i < subFiles.length; i++){
				if(subFiles[i].isDirectory()){
					deleteFiles(subFiles[i]);
				}
				System.out.println(subFiles[i].getName() + " is deleted...");
				subFiles[i].delete();
			}
			System.out.println(path + " is deleted...");
			path.delete();
		}
		return false;
	}
}
Advertisements

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s