Java Recursive Delete recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root)

Here you can find the source of recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root)

Description

recursively Delete Empty Parent Directories Up To Root

License

Open Source License

Declaration

public static void recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root) 

Method Source Code


//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;
        }
    }
}

Related

  1. recursivelyDelete(File aDirectory)
  2. recursivelyDelete(File dir)
  3. recursivelyDelete(final File root, final boolean deleteRoot)
  4. recursivelyDelete(String loc)
  5. recursivelyDeleteEmptyDirectories(File fileToDelete)
  6. recursivelyDeleteFile(File path)
  7. recursiveRemoveDir(File dir)
  8. recursiveRemoveDir(File directory)