package org.jeecg.modules.mdc.util;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.nio.file.Files;
|
import java.nio.file.StandardCopyOption;
|
|
/***
|
* DNC平移设备车间工具类
|
*/
|
public class DncCopyEquipment {
|
|
public static void CopyEquipmentPath(String OldPath,String NewPath){
|
if (!OldPath.equals(NewPath)) {
|
File oldDir = new File(OldPath);
|
File newDir = new File(NewPath);
|
// 创建新目录
|
if (!newDir.exists()) {
|
if (!newDir.mkdirs()) {
|
System.err.println("无法创建新目录: " + NewPath);
|
return;
|
}
|
}
|
// 遍历旧目录下的所有文件和子目录
|
if (oldDir.exists() && oldDir.isDirectory()) {
|
File[] files = oldDir.listFiles();
|
if (files != null) {
|
for (File file : files) {
|
try {
|
File destFile = new File(newDir, file.getName());
|
// 复制文件
|
Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
} catch (IOException e) {
|
System.err.println("文件平移过程中出现错误: " + e.getMessage());
|
}
|
}
|
}
|
}
|
// 删除旧目录
|
if (!oldDir.delete()) {
|
System.err.println("删除原目录失败: " + oldDir);
|
}
|
}
|
}
|
}
|