|
@@ -9,38 +9,61 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileFilter;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Paths;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
|
|
|
public class Test {
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
- Date d = new Date(1634433572000l);
|
|
|
-
|
|
|
- System.err.println(d);
|
|
|
-
|
|
|
-
|
|
|
- IndexRequest indexRequest = new IndexRequest();
|
|
|
- XContentBuilder builder;
|
|
|
- try {
|
|
|
- builder = JsonXContent.contentBuilder()
|
|
|
- .startObject()
|
|
|
- .startObject("query")
|
|
|
- .startObject("range")
|
|
|
- .startObject("time")
|
|
|
- .field("lte", 1634433572000l)
|
|
|
- .endObject()
|
|
|
- .endObject()
|
|
|
- .endObject()
|
|
|
- .endObject();
|
|
|
- indexRequest.source(builder);
|
|
|
- } catch (IOException e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
+ int day = 14;
|
|
|
+ day = day * 24 * 60 * 60 * 1000;
|
|
|
+ String bakDir = "D:\\SYSTEM\\Desktop\\temp\\test";
|
|
|
+ // 创建File对象
|
|
|
+ File dirFile = new File(bakDir);
|
|
|
+ if (dirFile.isDirectory()) {
|
|
|
+ //先获取目录下所有文件
|
|
|
+ long d = System.currentTimeMillis();
|
|
|
+ File[] files = dirFile.listFiles();
|
|
|
+ //按照文件创建时间升序排列
|
|
|
+ if (files != null && files.length > 0) {
|
|
|
+ Arrays.sort(files, Comparator.comparing(File::lastModified));
|
|
|
+ }
|
|
|
+ for (File file : files) {
|
|
|
+ if (d - file.lastModified() > day) {
|
|
|
+ FileUtils.delete(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- String source = indexRequest.source().utf8ToString();
|
|
|
- System.err.println(source);
|
|
|
+
|
|
|
+// Date d = new Date(1634433572000l);
|
|
|
+//
|
|
|
+// System.err.println(d);
|
|
|
+//
|
|
|
+//
|
|
|
+// IndexRequest indexRequest = new IndexRequest();
|
|
|
+// XContentBuilder builder;
|
|
|
+// try {
|
|
|
+// builder = JsonXContent.contentBuilder()
|
|
|
+// .startObject()
|
|
|
+// .startObject("query")
|
|
|
+// .startObject("range")
|
|
|
+// .startObject("time")
|
|
|
+// .field("lte", 1634433572000l)
|
|
|
+// .endObject()
|
|
|
+// .endObject()
|
|
|
+// .endObject()
|
|
|
+// .endObject();
|
|
|
+// indexRequest.source(builder);
|
|
|
+// } catch (IOException e) {
|
|
|
+// // TODO Auto-generated catch block
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// String source = indexRequest.source().utf8ToString();
|
|
|
+// System.err.println(source);
|
|
|
// Files.delete(Paths.get("D:\\SYSTEM\\Desktop\\temp\\zip"));
|
|
|
// File file = new File("D:\\SYSTEM\\Desktop\\temp\\624");
|
|
|
// FileUtils.deleteDirectory(file);
|