|
@@ -104,7 +104,38 @@ public class MonitorFileUtils {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- String[] childFilePaths = dir.list();
|
|
|
+ File[] childFiles = dir.listFiles();
|
|
|
+ if(childFiles == null || childFiles.length == 0) {
|
|
|
+ Configs.sysLog.warn("this dirFilePath is a empty dir \tdirFilePath:" + dirFilePath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (File childFile : childFiles) {
|
|
|
+ if(childFile != null && childFile.isDirectory()) {
|
|
|
+ removeBeforeTodayEmptyDirImpl(childFile.getAbsolutePath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 移除今天之前创建的空目录
|
|
|
+ * @param dirFilePath 文件夹目录
|
|
|
+ */
|
|
|
+ public static void removeBeforeTodayEmptyDirImpl(String dirFilePath) {
|
|
|
+ // 文件的上级目录
|
|
|
+ if(TextUtils.isEmpty(dirFilePath)) {
|
|
|
+ Configs.sysLog.warn("the dirFilePath is null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ File dir = new File(dirFilePath);
|
|
|
+ if(!dir.exists() || !dir.isDirectory()) {
|
|
|
+ Configs.sysLog.warn("this dirFilePath not exists or not dir \tdirFilePath:" + dirFilePath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ File[] childFiles = dir.listFiles();
|
|
|
DateFormat df = new SimpleDateFormat("yyyyMMdd");
|
|
|
Calendar ca = Calendar.getInstance();
|
|
|
ca.setTimeInMillis(dir.lastModified());
|
|
@@ -116,23 +147,24 @@ public class MonitorFileUtils {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(null == childFilePaths || childFilePaths.length == 0) {
|
|
|
+ if(null == childFiles || childFiles.length == 0) {
|
|
|
// 不是同一天
|
|
|
if (dir.delete()) {
|
|
|
Configs.sysLog.info("Dir is delete suc:" + dirFilePath);
|
|
|
} else {
|
|
|
Configs.sysLog.info("Dir is delete fail:" + dirFilePath);
|
|
|
}
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- for (String childFilePath : childFilePaths) {
|
|
|
- removeBeforeTodayEmptyDir(childFilePath);
|
|
|
+ for (File childFile : childFiles) {
|
|
|
+ if(childFile != null && childFile.isDirectory()) {
|
|
|
+ removeBeforeTodayEmptyDirImpl(childFile.getAbsolutePath());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 检测备份目录并返回 备份目标 文件(路径)
|
|
|
*
|