Java File Path Delete deleteFolder(String path)

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

Description

deleteFolder

License

Open Source License

Parameter

Parameter Description
path a parameter

Declaration

public static int deleteFolder(String path) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    /**/*  w ww .  ja  va 2s . co  m*/
     * deleteFolder
     * 
     * @param path
     * @return
     */
    public static int deleteFolder(String path) {

        int res = 1;
        File dir = new File(path);

        String[] files = dir.list();

        if (files != null && files.length > 0) {

            for (int i = 0; i < files.length; i++) {

                File temp = new File(path + "/" + files[i]);

                if (temp.isDirectory()) {
                    res += deleteFolder(temp.getAbsolutePath());
                }

                try {
                    temp.delete();
                } catch (Exception ee) {
                    return -1;
                }
            }

        }

        dir.delete();

        return res;
    }
}

Related

  1. deleteFolder(String path)
  2. deleteFolder(String path)
  3. deleteFolder(String path)
  4. deleteFolder(String path)
  5. deleteFolder(String path)
  6. deleteFolder(String path)
  7. deleteFolder(String pathToRootFolder)
  8. deleteFolder(String pFolderPath)
  9. deleteFolder(String sPath)