36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import fs from "fs";
|
||
import path from "path";
|
||
import * as dicomParser from "dicom-parser"; /* */
|
||
import { ipcMain } from "electron";
|
||
|
||
// 定义一个异步函数来递归地查找.dcm文件
|
||
const findDcmFiles = async (
|
||
dir: string,
|
||
fileList: string[] = []
|
||
): Promise<string[]> => {
|
||
const files = await fs.promises.readdir(dir, { withFileTypes: true });
|
||
await Promise.all(
|
||
files.map(async (file) => {
|
||
const filePath = path.join(dir, file.name);
|
||
if (file.isDirectory()) {
|
||
await findDcmFiles(filePath, fileList); // 递归调用以遍历子目录
|
||
} else if (file.name.endsWith(".dcm")) {
|
||
fileList.push(filePath); // 如果文件是.dcm文件,添加到列表中
|
||
}
|
||
})
|
||
);
|
||
return fileList;
|
||
};
|
||
|
||
const registerIpcMainHandlers = () => {
|
||
ipcMain.on("parseDicom", async (event, file: string) => {
|
||
const rootFolder = path.dirname(file);
|
||
const fileList = await findDcmFiles(rootFolder);
|
||
console.log("rootFolder", rootFolder);
|
||
console.log("fileList", fileList);
|
||
// event.sender.send("parseDicomResponse", files);
|
||
});
|
||
};
|
||
|
||
export default registerIpcMainHandlers;
|