每天定时监测是否包含当天时间的文件夹生成
@SpringBootApplication
@EnableScheduling
public class ScheduledTasks {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
@Scheduled(cron = "0 0 17 * * ?") // 每天下午5点执行一次
public void checkFolderExistence() {
String folderPrefix = "****_" + dateFormat.format(new Date()); // 文件夹名称前缀
String folderPath = "path/to/your/folder/"; // 文件夹所在路径
File folderDir = new File(folderPath);
File[] files = folderDir.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory() && file.getName().contains(folderPrefix)) {
System.out.println("Folder " + file.getName() + " exists.");
}
}
} else {
System.out.println("No folder with prefix " + folderPrefix + " exists.");
}
}
}