Sometimes You Just Need to Remove All SVN Metadata Folders

Posted by & filed under Uncategorized.

Rather than delete each SVN meta-data folder by hand, try automating.  Here’s some code that might help.

import java.io.File;

public class RemoveSVNMetaData {

	public static void main(String[] args){
		System.out.println("Remove SVN Metadata for " + args[0]);
		File f = new File(args[0]);
		if(f.isDirectory()){
			checkDirectory(f);			
		}
		else {
			System.out.println(args[0] + " is not a directory.");
		}
		
	}
	
	public static void checkDirectory(File dir){
		final File[] files = dir.listFiles();
		for(File file:files){
			if (file.isDirectory() && file.getName().startsWith(".svn")) {
				System.out.println("Removing " + file.getName());
				removeDirectory(file);
				file.delete();
			}
			else if(file.isDirectory()){
				checkDirectory(file);
			}
		}
	}
	
	public static void removeDirectory(File dir){
		final File[] files = dir.listFiles();
		for(File file:files){
			if(file.isDirectory()){
				System.out.println("Removing " + file.getName());
				removeDirectory(file);
				file.delete();
			}
			else {
				System.out.println("Removing " + file.getName());
				file.delete();
			}
		}
	}
	
	
}