Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
76441a2a
Commit
76441a2a
authored
Dec 08, 2022
by
DESKTOP-BQLVS7A\admin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ugp测试在服务器定时删除文件夹下的文件
parent
51ef7f2c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
16 deletions
+42
-16
CylinderSchedulerJob.java
...amos/boot/module/ugp/api/quartz/CylinderSchedulerJob.java
+42
-16
No files found.
amos-boot-system-ugp/amos-boot-module-ugp-api/src/main/java/com/yeejoin/amos/boot/module/ugp/api/quartz/CylinderSchedulerJob.java
View file @
76441a2a
...
...
@@ -6,7 +6,11 @@ import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.stream.Stream
;
@Component
@EnableScheduling
...
...
@@ -15,24 +19,46 @@ public class CylinderSchedulerJob {
/**
* 每天3点-删除图片
*/
@Scheduled
(
cron
=
"${cylinder-early-warning-cron:0 0 19 * * ?}"
)
public
void
clean
()
{
dayReport
(
new
File
(
"/home/yeejoin/ugp/minio-data/upload/common/ugp/qrcode"
));
}
// @Scheduled(cron = "${cylinder-early-warning-cron:0 0 19 * * ?}")
// public void clean() {
// dayReport(new File("/home/yeejoin/ugp/minio-data/upload/common/ugp/qrcode"));
// }
// public static void dayReport(File file) {
//// file.isAbsolute();
// if (!ValidationUtil.isEmpty(file.listFiles())) {
// for (File f : file.listFiles()) {
// //实现递归
// if (f.isDirectory()) {
// dayReport(f);
// }
// //清理文件
// f.delete();
// System.out.println(f.getName() + "已清理!!!");
// }
// }
// }
@Scheduled
(
cron
=
"${cylinder-early-warning-cron:0 0 12 * * ?}"
)
public
void
cleanFile
()
throws
IOException
{
deleteFile
(
"/home/yeejoin/ugp/minio-data/upload/common/ugp/ceshi"
);
}
public
static
void
dayReport
(
File
file
)
{
// file.isAbsolute();
if
(!
ValidationUtil
.
isEmpty
(
file
.
listFiles
()))
{
for
(
File
f
:
file
.
listFiles
())
{
//实现递归
if
(
f
.
isDirectory
())
{
dayReport
(
f
);
}
//清理文件
f
.
delete
();
System
.
out
.
println
(
f
.
getName
()
+
"已清理!!!"
);
}
public
static
void
deleteFile
(
String
destDirPath
)
throws
IOException
{
System
.
out
.
println
(
"开始删除文件 destDirPath:{}"
);
Process
p
;
InputStreamReader
inputStreamReader
=
null
;
BufferedReader
br
=
null
;
String
co
=
"rm -rf "
+
destDirPath
;
try
{
p
=
Runtime
.
getRuntime
().
exec
(
co
);
inputStreamReader
=
new
InputStreamReader
(
p
.
getInputStream
());
br
=
new
BufferedReader
(
inputStreamReader
);
System
.
out
.
println
(
"执行删除任务完毕 删除命令:{} 时间:{}"
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
br
.
close
();
}
}
// public static void main(String[] args) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment