Java Delete Directory deleteFiles(List files)

Here you can find the source of deleteFiles(List files)

Description

This deletes the files in the given list.

License

Open Source License

Parameter

Parameter Description
files The files to delete

Return

List of unsuccessfully deleted files

Declaration

public static List<File> deleteFiles(List<File> files) 

Method Source Code

//package com.java2s;
/*/*from  w  ww  .  j av  a  2 s  .c  o m*/
 * Copyright 1997-2016 Unidata Program Center/University Corporation for Atmospheric Research
 * Copyright 2010-2015 Jeff McWhirter
 * 
 * This library 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 2.1 of the License, or (at
 * your option) any later version.
 * 
 * This library 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 library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 */

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * This deletes the files in the given list.
     * It will return  a list of those files where file.delete was not successful
     *
     * @param files The files to delete
     * @return List of unsuccessfully deleted files
     */
    public static List<File> deleteFiles(List<File> files) {
        List<File> notDeleted = new ArrayList<File>();
        for (File f : files) {
            if (!f.delete()) {
                notDeleted.add(f);
            }
        }
        return notDeleted;
    }
}

Related

  1. deleteFiles(FileFilter filter)
  2. deleteFiles(final ArrayList files)
  3. deleteFiles(final File directory, final String regexPattern)
  4. deleteFiles(final File file)
  5. deleteFiles(final File... files)
  6. deleteFiles(String dir)
  7. deleteFiles(String dir, String... files)
  8. deleteFiles(String directory, FileFilter filter, boolean recursive)
  9. deleteFiles(String directoryName)