Java File Path Delete deleleFiles(String regex, String path)

Here you can find the source of deleleFiles(String regex, String path)

Description

delele Files

License

Open Source License

Declaration

public static int deleleFiles(String regex, String path) 

Method Source Code


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

import java.io.File;

public class Main {
    public static int deleleFiles(String regex, String path) {
        int rtn = 0;

        if (path != null && regex != null) {
            File folder = new File(path);
            File[] files = folder.listFiles();
            for (int i = 0; i < files.length; i++) {
                String fname = files[i].getName();
                if (fname.matches(regex)) {
                    if (files[i].delete()) {
                        rtn++;//from  w  w  w  . ja  v  a 2 s. c  om
                    }
                }
            }
        }

        return rtn;
    }

    public static int deleleFiles(String regex) {
        return deleleFiles(regex, ".");
    }
}

Related

  1. delAllFile(String path)
  2. delAllFiles(File dir, String prefix)
  3. delAllFiles(File dir, String suffix)
  4. delDir(String path)
  5. delDirAndFile(String tempath)
  6. delEmptyPath(String path)
  7. delete(File path)
  8. delete(File path)
  9. delete(File path)