Java Delete Directory deleteFiles(String sDir, String sSearch)

Here you can find the source of deleteFiles(String sDir, String sSearch)

Description

delete Files

License

Open Source License

Declaration

public static void deleteFiles(String sDir, String sSearch) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static void deleteFiles(String sDir, String sSearch) throws IOException {

        File dir = new File(sDir).getCanonicalFile();
        File[] files = dir.listFiles();

        for (File f : files) {
            if (sSearch.equals("*")) {
                f.delete();//w  ww  .  j av  a 2 s .c  om
            } else {
                String[] sHold = sSearch.split(",");
                for (String s : sHold) {
                    if (s.indexOf("*.") >= 0) {
                        if (f.getName().indexOf(s.substring(s.indexOf(".") + 1)) >= 1) {
                            f.delete();
                        }
                    }
                }
            }
        }
    }
}

Related

  1. deleteFiles(String dir, String... files)
  2. deleteFiles(String directory, FileFilter filter, boolean recursive)
  3. deleteFiles(String directoryName)
  4. deleteFiles(String fileName)
  5. deleteFiles(String root, String mask)
  6. deleteFiles(String[] filenames)
  7. deleteFilesAndDir(List files)
  8. deleteFilesAndSubDirs(File dir)
  9. deleteFilesFromDirectory(final String dirNameIn, final String filePrefixIn)