You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.6 KiB

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* @author lwy
*/
public class CreateWorkFolder {
public static void main(String[] args) {
// 获取今天的日期,并将其格式化为 "yyyy-MM-dd" 的字符串
LocalDate today = LocalDate.now();
String dateStr = today.format(DateTimeFormatter.ofPattern("M-d"));
// 创建今天日期的目录
Path dirPath = Paths.get("X:\\" + dateStr);
createFolder(dirPath);
// 在目录下创建三个子目录
String[] dirs = {"pic", "pic - 副本", "video", "修改后"};
for (String subdir : dirs) {
Path subdirPath = Paths.get(dirPath.toString(), subdir);
createFolder(subdirPath);
}
// 在目录下创建一个以今天日期命名的txt文件
Path filePath = Paths.get(dirPath.toString(), dateStr + ".txt");
if (Files.exists(filePath)) {
System.out.println("File already exists1: " + filePath);
} else {
try {
Files.createFile(filePath);
System.out.println("File created: " + filePath);
} catch (IOException e) {
System.out.println("Failed to create file: " + e.getMessage());
}
}
// 在video目录下创建一个转换视频文件
Path sourcePath = Paths.get("fastConvertMPG2mp4.bat");
Path videoConvertFile = Paths.get(dirPath.toString()+"\\video").resolve("fastConvertMPG2mp4.bat");
if (Files.exists(videoConvertFile)) {
System.out.println("File already exists2: " + videoConvertFile);
} else {
try {
Files.copy(sourcePath, videoConvertFile);
System.out.println("File created: " + videoConvertFile);
} catch (IOException e) {
System.out.println("Failed to create file: " + e.getMessage());
}
}
System.out.println("文件夹和文件创建结束!!!");
}
static void createFolder(Path subdirPath) {
if (Files.exists(subdirPath)) {
System.out.println("Directory already exists: " + subdirPath);
} else {
try {
Files.createDirectory(subdirPath);
System.out.println("Directory created: " + subdirPath);
} catch (IOException e) {
System.out.println("Failed to create directory: " + e.getMessage());
}
}
}
}