Java File Path Delete delFiles(String path)

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

Description

del Files

License

Open Source License

Declaration

public static boolean delFiles(String path) 

Method Source Code


//package com.java2s;
/*//from w ww  .  j  av a2  s.  c o  m
 * @(#)FileHelper.java      Created at 2013-2-24
 * 
 * Copyright (c) 2011-2013 azolla.org All rights reserved.
 * Azolla PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 
 */

import java.io.File;

import com.google.common.base.Preconditions;

public class Main {
    /**
     * Delete all document under this directory.
     * if the file is document delete it.
     * 
     * @param file document or directory
     * @return will return true with out false when some empty document delete failure
     */
    public static boolean delFiles(File file) {
        Preconditions.checkNotNull(file);
        boolean ret = true;
        if (file.exists()) {
            if (file.isDirectory() && file.list() != null) {
                for (File f : file.listFiles()) {
                    if (!f.isDirectory()) {
                        ret = ret && f.delete();
                    }
                }
            } else {
                ret = ret && file.delete();
            }
        }
        return ret;
    }

    /**
     * @see org.azolla.io.FileHelper#delFiles(File)
     */
    public static boolean delFiles(String path) {
        return delFiles(new File(path));
    }
}

Related

  1. delFile(String filePathAndName)
  2. DelFile(String in_Path, ArrayList arrFileList)
  3. delFile(String path)
  4. delFile(String pathName)
  5. delFileIfExists(String path)
  6. delTree(String path)