Here you can find the source of deleteEmptyDir(File dstPath)
Parameter | Description |
---|---|
dstPath | a parameter |
private static boolean deleteEmptyDir(File dstPath)
//package com.java2s; /*/*from ww w . j a v a 2 s . c o m*/ * Copyright 2007 Pentaho Corporation. All rights reserved. * * This software was developed by Pentaho Corporation and is provided under the terms * of the Mozilla Public License, Version 1.1, or any later version. You may not use * this file except in compliance with the license. If you need a copy of the license, * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho * BI Platform. The Initial Developer is Pentaho Corporation. * * Software distributed under the Mozilla Public License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to * the license for the specific language governing your rights and limitations. * * Created * @author * */ import java.io.File; import java.io.IOException; public class Main { /** * deletes Empty directories * * @param dstPath * @return */ private static boolean deleteEmptyDir(File dstPath) { Boolean result = false; if (dstPath.exists()) { try { delete(dstPath); } catch (IOException e) { e.printStackTrace(); } } return result; } /** * deletes Empty directories * * @param file * @throws IOException */ private static void delete(File file) throws IOException { if (file.isDirectory()) { if (file.list().length == 0) { file.delete(); } else { String files[] = file.list(); for (String temp : files) { File fileDelete = new File(file, temp); delete(fileDelete); } if (file.list().length == 0) { file.delete(); } } } } }