递归删除指定文件夹

public class TestDeleSVN {
//指定路径
public static void main(String[] args) {
deleteSVN(“F:\System”);
}

private static void deleteSVN(String s) {
    File[] files=new File(s).listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });
    for (File file:files){
        //指定删除的文件名
        if (file.isHidden() && file.getName().equals(".svn") ){
            String path=file.getAbsolutePath();
            System.out.println("正在删除:"+path);
            try {
                Process process=Runtime.getRuntime().exec("cmd /C rd /S /Q " + path);
                process.waitFor();
                System.out.println("成功删除:"+path);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("删除失败:"+path);
            }
        }else {
            //递归
            deleteSVN(file.getAbsolutePath());
        }
    }
}

}

你可能感兴趣的:(递归删除指定文件夹)