Here you can find the source of recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root)
public static void recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static void recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root) { File dir = new File(path); while (!root.equals(dir.getPath().replace('\\', '/'))) { if (dir.isDirectory()) { String[] files = dir.list(); if (files != null && files.length == 0) { dir.delete();//from w w w .ja v a2 s . c om } } dir = dir.getParentFile(); if (dir == null) break; } } }