Java Delete Directory deleteFiles(File directory)

Here you can find the source of deleteFiles(File directory)

Description

Non-recursive delete for all files in the given directory.

License

Apache License

Parameter

Parameter Description
directory a parameter

Declaration


public static void deleteFiles(File directory) 

Method Source Code

//package com.java2s;
/*//from   w  ww . j ava2  s  .com
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.File;

public class Main {
    /**
     * Non-recursive delete for all files in the given directory.
     * Files in sub-directories not deleted.
     * @param directory
     */
    // TODO remove as not in use?
    public static void deleteFiles(File directory) {
        if (directory.isDirectory()) {
            String[] children = directory.list();
            for (int i = 0; i < children.length; i++) {
                new File(directory, children[i]).delete();
            }
        }
    }
}

Related

  1. deleteDirectoryContents(final File dir, int deleteDirLevel, int level)
  2. deleteFiles(File dir)
  3. deleteFiles(File dir)
  4. deleteFiles(File directory)
  5. deleteFiles(File directory)
  6. deleteFiles(File directory, String prefix)
  7. deleteFiles(File docFolder)
  8. deleteFiles(File f, boolean del_self)
  9. deleteFiles(File file)