Here you can find the source of deleteEmptyParents(final File path)
Parameter | Description |
---|---|
path | directory to start in. |
public static void deleteEmptyParents(final File path)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**//from www . j a va 2 s .c o m * Delete path and any empty parent directories. * * @param path * directory to start in. */ public static void deleteEmptyParents(final File path) { deleteEmptyParents(path, null); } /** * Delete path and any empty parent directories up to the stopAt point. * * @param path * direcotry to start in * @param stopAt * directory to stop at */ public static void deleteEmptyParents(final File path, final File stopAt) { File parent = path; // Loop while parent is not null and we are not yet at the stopAt point while (parent != null && !parent.equals(stopAt)) { try { parent.delete(); parent = parent.getParentFile(); } catch (Exception e) { e.printStackTrace(); break; } } } }