package cn.lls;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import cn.lls.utils.FileSort;
import cn.lls.utils.TypeConvertUtil;
public class Tes {
static int dayInt;
static long fileL;
static int no = 0;
static List<Long> list2;
static long totalSize = 0;
// 递归方法
public static void deepList(File file) {
if (file.isFile() || (0 == file.list().length)) {
return;
} else {
File[] files = file.listFiles();
files = FileSort.sort(files);
for (File f : files) {
if (f.isFile()) {
String fileName = f.getName();
if (!fileName.equals("Log" + ".txt")) {
String fileDay = fileName.substring(3, 13);
System.out.println(fileDay);
Date d = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
dayInt = (int) TypeConvertUtil.getIntervalDays(fileDay, df.format(d));
System.out.print("离今天有:" + dayInt + " 天了 ");
fileL = f.length();
list2 = new ArrayList<>();
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(dayInt, no);
list2.add(map.get(dayInt), fileL);
for (int i = 0; i < list2.size(); i++) {
totalSize += list2.get(i);
System.out.println("总大小:" + totalSize + " Bytes " + (totalSize / 1024 / 1024) + " MB");
if (totalSize > 12312) {
f.delete();
}
}
}
}
}
}
}
public static void main(String[] args) {
File f = new File("D:/aaa");
deepList(f);
}
}