Java Date Format Pattern subFiles(String formatString, File[] files)

Here you can find the source of subFiles(String formatString, File[] files)

Description

Gets a list of backups

License

Open Source License

Parameter

Parameter Description
formatString Format of the file name
files A list of files

Declaration

private static void subFiles(String formatString, File[] files) 

Method Source Code


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

import java.io.File;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    private static final TreeMap<Date, File> backupList = new TreeMap<>();

    /**//from  w  ww  . j  a  v a 2  s .c  o m
     * Gets a list of backups
     *
     * @param formatString Format of the file name
     * @param files        A list of files
     */
    private static void subFiles(String formatString, File[] files) {
        for (File file : files) {
            if (file.isDirectory()) {
                subFiles(formatString, file.listFiles()); // Calls same method again.
            } else {
                if (file.getName().endsWith(".zip")) {
                    String dateString = file.getName();
                    DateFormat format = new SimpleDateFormat(formatString, Locale.ENGLISH);
                    try {
                        Date date = format.parse(dateString);
                        backupList.put(date, file);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

Related

  1. getSupportedFormats()
  2. isEqual(String d1, String d2, String format)
  3. isValidFormat(String format, String value)
  4. log(String format, Object... args)
  5. logFormat(String msg)
  6. subtraiHora(String horaFim, String horaIni, String formatoHora)
  7. sysdateStringddMMyyyyhhmmss()
  8. toThreadSafeFormat(final String format)
  9. traceInformation(String message)