Java Delete Folder deleteFolderContents(File folder)

Here you can find the source of deleteFolderContents(File folder)

Description

delete Folder Contents

License

Apache License

Declaration

public static boolean deleteFolderContents(File folder) 

Method Source Code

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

import java.io.File;

public class Main {

    public static boolean deleteFolderContents(File folder) {
        File[] files = folder.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isFile()) {
                    if (!file.delete()) {
                        return false;
                    }//from   www  .  ja va 2 s. c  o  m
                } else {
                    if (!deleteFolder(file)) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

    public static boolean deleteFolder(File folder) {
        return deleteFolderContents(folder) && folder.delete();
    }
}

Related

  1. deleteFolder(final String folder)
  2. deleteFolder(String folder)
  3. deleteFolder(String folder)
  4. deleteFolder(String name)
  5. deleteFolderContents(File folder)
  6. deleteFolderContents(File folder)
  7. deleteFolderIfEmpty(File f)
  8. deleteFolderRec(File dir)
  9. deleteFolderRecursive(File folder)