Java Directory Clear cleanDirectory(File path)

Here you can find the source of cleanDirectory(File path)

Description

clean Directory

License

Open Source License

Declaration

static public void cleanDirectory(File path) 

Method Source Code

//package com.java2s;
/*//from  w w w.j a  va2  s . c  o  m
 * Copyright (C) 2012 Calenria <https://github.com/Calenria/> and contributors
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3.0 of the License, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see
 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
 */

import java.io.File;

public class Main {
    static public void cleanDirectory(File path) {
        if (path.exists()) {
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    if (!files[i].getName().equals("ramdisk")) {
                        files[i].delete();
                    }

                }
            }
        }
    }

    static public boolean deleteDirectory(File path) {
        if (path.exists()) {
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    files[i].delete();
                }
            }
        }
        return (path.delete());
    }
}

Related

  1. cleanDirectory(File directory)
  2. cleanDirectory(File directory)
  3. cleanDirectory(File directory)
  4. cleanDirectory(File directory)
  5. cleanDirectory(File directory)
  6. cleanDirectory(final File directory)
  7. cleanDirectory(final File directory)
  8. cleanDirectory(IProgressMonitor monitor, File directory)
  9. cleanDirectory(IProgressMonitor monitor, File directory, File base, int step)