请选择 进入手机版 | 继续访问电脑版
MSIPO技术圈 首页 IT技术 查看内容

钻孔模型和刨面模型osg合并

2023-07-13

import java.io.File;
import java.util.Random;

public class MvD {
public static void main(String[] args) {
File[] fileListmulu = filemulu.listFiles();
File sourceDir = new File(“D:\temp\test\刨面”);
File destinationDir = new File(“D:\temp\test\刨面整理”);
// 移动目录操作
moveDirectory(sourceDir, destinationDir);
}

/**
 * 移动目录操作,包括其中的所有文件及子目录
 *
 * @param source      源目录
 * @param destination 目标目录
 */
public static void moveDirectory(File source, File destination) {
    //获取所有钻孔目录
    File[] fileListzk = source.listFiles();
    for (File filezk : fileListzk) {
        //获取所有地层目录
        File[] fileListdc = filezk.listFiles();
        for (File filedc : fileListdc) {
            String dcname = filedc.getName();
            // 目标目录创建
            File destinationDir = new File("D:\\temp\\test\\刨面整理\\" + dcname);
            destinationDir.mkdir();
            //获取所有模型文件
            File[] fileListmx = filedc.listFiles();
            for (File filemx : fileListmx) {
                String fileName = "model";
                int count = 0;
                File sourceFile = new File(String.valueOf(filemx));
                File destinationFile;
                if (filemx.getName().endsWith(".osg")) {
                    destinationFile = new File(destinationDir, fileName + getRandomString(10) + ".osg");
                    count++;
                } else {
                    String fileN = filemx.getName();
                    destinationFile = new File(destinationDir, fileN);
                }
                sourceFile.renameTo(destinationFile);
                System.out.println(sourceFile.getAbsolutePath() + " 移动到 " + destinationFile.getAbsolutePath());
            }

// File sourceFile = new File(source, dcname);
}
}

    // 移动完成后删除原目录
    source.delete();
    System.out.println(source.getAbsolutePath() + " 目录已删除.");
}

/**
 * 随机生成字符串
 *
 * @param length 随机字符串长度
 */
public static String getRandomString(int length) {
    String base = "abcdefghijklmnopqrstuvwxyz0123456789";
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < length; i++) {
        int number = random.nextInt(base.length());
        sb.append(base.charAt(number));
    }
    return sb.toString();
}

}

相关阅读

手机版|MSIPO技术圈 皖ICP备19022944号-2

Copyright © 2024, msipo.com

返回顶部