Java File Path Delete deleteDirectory(File path)

Here you can find the source of deleteDirectory(File path)

Description

delete Directory

License

Apache License

Parameter

Parameter Description
path a parameter

Declaration

static public boolean deleteDirectory(File path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**// w w w.ja v a2 s. c  o  m
     * 
     * @param path
     * @return
     */
    static public boolean deleteDirectory(File path) {
        if (path.exists()) {
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    files[i].delete();
                }
            }
        }
        return (path.delete());
    }

    /**
     * List files in a given directory
     * 
     * */
    static public String[] listFiles(String inputdir) {
        File dir = new File(inputdir);

        String[] children = dir.list();
        if (children == null) {
            // Either dir does not exist or is not a directory
        } else {
            for (int i = 0; i < children.length; i++) {
                // Get filename of file or directory
                String filename = children[i];
            }
        }

        return children;
    }
}

Related

  1. deleteDirectory(File directoryPath)
  2. deleteDirectory(File path)
  3. deleteDirectory(File path)
  4. deleteDirectory(File path)
  5. deleteDirectory(File path)
  6. deleteDirectory(File path)
  7. deleteDirectory(File path)
  8. deleteDirectory(File path)
  9. deleteDirectory(File path)