Java Folder Delete clearFilesOnPath(String path)

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

Description

clear Files On Path

License

Apache License

Declaration

public static boolean clearFilesOnPath(String path) 

Method Source Code


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

import java.io.File;

public class Main {
    public static boolean clearFilesOnPath(String path) {
        File dir = new File(path);

        if (!dir.exists()) {
            System.out.println(path + " does not exists");
            return false;
        }//from  ww  w  .ja v  a 2s . c o  m

        if (!dir.isDirectory()) {
            System.out.println(path + " is not directory");
            return false;
        }

        File[] files = dir.listFiles();

        System.out.println("deleting " + path + " (" + files.length + " files)");

        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                // System.out.println("deleting " + files[i] );
                if (!files[i].delete()) {
                    return false;
                }
            }
        }

        return true;
    }
}

Related

  1. clearDir(File dir)
  2. clearDir(File dir)
  3. clearDir(File dir)
  4. clearDir(File dir)
  5. clearFiles(File dir)
  6. clearFolder(File f)
  7. clearFolder(File[] children)
  8. clearFolder(String directoryLocation)
  9. clearFolder(String folder)