Java File Path Delete deleteDb(String path)

Here you can find the source of deleteDb(String path)

Description

delete Db

License

Open Source License

Declaration

static public void deleteDb(String path) 

Method Source Code


//package com.java2s;
/*//ww w  .j  a v a 2s  . c  o m
  Kvalobs - Free Quality Control Software for Meteorological Observations 
    
  $Id: DbTestUtil.java,v 1.1.2.2 2007/09/27 09:02:20 paule Exp $                                                       
    
  Copyright (C) 2007 met.no
    
  Contact information:
  Norwegian Meteorological Institute
  Box 43 Blindern
  0313 OSLO
  NORWAY
  email: kvalobs-dev@met.no
    
  This file is part of KVALOBS
    
  KVALOBS is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License as 
  published by the Free Software Foundation; either version 2 
  of the License, or (at your option) any later version.
      
  KVALOBS 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
  General Public License for more details.
      
  You should have received a copy of the GNU General Public License along 
  with KVALOBS; if not, write to the Free Software Foundation Inc., 
  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

import java.io.File;

public class Main {
    static public void deleteDb(String path) {
        File dbdir = new File(path);

        if (dbdir.exists()) {
            if (dbdir.isDirectory()) {
                String[] files = dbdir.list();
                int dirs = 0;

                for (int i = 0; i < files.length; i++) {
                    File f = new File(path + "/" + files[i]);
                    if (f.isFile()) {
                        f.delete();
                    } else {
                        dirs++;
                    }
                }

                if (dirs == 0)
                    dbdir.delete();
            }
        }
    }
}

Related

  1. deleteBlankPath(String path)
  2. deleteChildDirectoriesExcept(File path, String... directoriesToSkip)
  3. deleteContents(File dirPath, List failures)
  4. deleteContentsOnly(final String srcPath)
  5. deleteDataFiles(final Collection paths)
  6. deleteDir(File delDir)
  7. deleteDir(File dir)
  8. deleteDir(File dir)
  9. deleteDir(File dir)