import java.io.*;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class docx {
    public static void main(String[] args) {
        String sourceDirectory = "C:\\code\\Data-ui\\src2\\views"; // 修改为你的代码目录路径
        String outputFile = "C:\\code\\Data-ui\\前端.doc"; // 修改为输出的文本文件名

        String[] allowedExtensions = {".vue"}; // 添加需要合并的扩展名

        try {
            PrintWriter writer = new PrintWriter(outputFile);

            List<File> codeFiles = new ArrayList<>();
            collectCodeFiles(sourceDirectory, codeFiles, allowedExtensions);

            for (File file : codeFiles) {
                //  writer.println("=== File: " + file.getAbsolutePath() + " ===");
                List<String> lines = Files.readAllLines(file.toPath());
                for (String line : lines) {
                    writer.println(line);
                }
                writer.println("\n");
                writer.println("\n");
                writer.println("\n");
                writer.println("\n");
            }

            writer.close();
            System.out.println("Code collection completed.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void collectCodeFiles(String directoryPath, List<File> codeFiles, String[] allowedExtensions) {
        File directory = new File(directoryPath);
        File[] files = directory.listFiles();

        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    collectCodeFiles(file.getAbsolutePath(), codeFiles, allowedExtensions);
                } else if (file.isFile() && hasAllowedExtension(file.getName(), allowedExtensions)) {
                    codeFiles.add(file);
                }
            }
        }
    }

    private static boolean hasAllowedExtension(String fileName, String[] allowedExtensions) {
        String extension = getFileExtension(fileName);
        return Arrays.asList(allowedExtensions).contains(extension);
    }

    private static String getFileExtension(String fileName) {
        int dotIndex = fileName.lastIndexOf(".");
        if (dotIndex > 0 && dotIndex < fileName.length() - 1) {
            return fileName.substring(dotIndex);
        }
        return "";
    }
}
苏ICP备18039385号