Lius
2025-03-21 87874019eefbe03dd429b5b7eed49d963ef03c88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);
            }
        }
    }
}