package com.xypower.common;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class FileUtils {




    public static boolean DeleteFilesInPath(String path, long seconds) {
        File pathFile = new File(path);
        if (!pathFile.exists() || !pathFile.isDirectory()) {
            return false;
        }

        long ts = System.currentTimeMillis();
        long diff = 0;
        seconds *= 1000;

        List<File> files = new ArrayList<File>();

        for (File f : pathFile.listFiles()) {
            if (!f.isFile()) {
                continue;
            }
            diff = ts - f.lastModified();
            if (diff > seconds) {
                files.add(f);
            }
        }

        for (File f : files) {
            f.delete();
        }

        return true;
    }

}
