Java Directory Clean cleanDir(final File dir, final String exclude)

Here you can find the source of cleanDir(final File dir, final String exclude)

Description

clean Dir

License

Open Source License

Declaration

public static void cleanDir(final File dir, final String exclude) 

Method Source Code


//package com.java2s;
/*=============================================================================#
 # Copyright (c) 2009-2015 Stephan Wahlbrink (WalWare.de) and others.
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the GNU Lesser General Public License
 # v2.1 or newer, which accompanies this distribution, and is available at
 # http://www.gnu.org/licenses/lgpl.html
 # /*from   ww w.ja v a 2  s.  c  o m*/
 # Contributors:
 #     Stephan Wahlbrink - initial API and implementation
 #=============================================================================*/

import java.io.File;

public class Main {
    public static void cleanDir(final File dir, final String exclude) {
        final String[] children = dir.list();
        for (final String child : children) {
            if (child.equals(exclude)) {
                continue;
            }
            final File file = new File(dir, child);
            if (file.isDirectory()) {
                delDir(file);
            } else {
                file.delete();
            }
        }
    }

    public static boolean delDir(final File dir) {
        final String[] children = dir.list();
        for (final String child : children) {
            final File file = new File(dir, child);
            if (file.isDirectory()) {
                delDir(file);
            } else {
                file.delete();
            }
        }
        return dir.delete();
    }
}

Related

  1. cleanDir(File dir)
  2. cleanDir(File dir)
  3. cleanDir(File directory)
  4. cleanDir(final File dir)
  5. cleanDir(final File dir)
  6. cleanDir(final String luceneDir)
  7. cleanDir(String dir)
  8. cleanDir(String directory)
  9. cleanDir(String path)