/* 准备工作 */ // 交通事故 var path = require("path"); var fs = require("fs"); const express = require('express'); const pgclient = require("../DataBase/Postgresql/pgClient.js") const fileaddres = require("./fileaddres.js") const { Pool, Client } = require('pg') const pool = new Pool({ user: 'postgres', host: '39.107.237.131', database: 'taijiu0820db', password: '123456', port: 5432, }) // let indexnumber = 0 /* 读取 */ /* 同步读取 */ // 第一级目录里面所有的 文件夹 // 第一层 过滤 var ppChildren = fs.readdirSync(`${fileaddres.datadiskpath}`); let path2Arr = [] ppChildren.forEach(ppchild => { let path2 = path.join(`${fileaddres.datadiskpath}`, ppchild); var stat = fs.lstatSync(path2); if (stat.isDirectory()) { path2Arr.push(path2) } }) path2Arr.forEach(path2 => { let path3Arr = []; var path3NamesArr = fs.readdirSync(path2); path3NamesArr.forEach(path3Name => { let path3 = path.join(path2, path3Name); var stat = fs.lstatSync(path3); if (stat.isDirectory()) { path3Arr.push(path3) } }) path3Arr.forEach(path3 => { let path4Arr = [] var path4NamesArr = fs.readdirSync(path3); path4NamesArr.forEach(path4Name => { let path4 = path.join(path3, path4Name); var stat4 = fs.lstatSync(path4); if (stat4.isDirectory()) { path4Arr.push(path4) } }) path4Arr.forEach(path4 => { var file5NamesArr = fs.readdirSync(path4); file5NamesArr.forEach(file5Name => { let file5Path = path.join(path4, file5Name); let name = file5Name.substring(0, file5Name.length - 4); let year = ""; let Url = ""; let newyear = ""; let serverUrl = ""; let type = ""; if (path4.indexOf("IncidentRecord") != -1) { type = "事件记录" year = path4.split('IncidentRecord\\'); newyear = year[1].split('\\'); // console.log(year); Url = year[1].replace(/\\/g, "/"); serverUrl = `${fileaddres.fileserver}` + "IncidentRecord/" + Url + "/" + file5Name; } if (path4.indexOf("ConserveRecord") != -1) { type = "养护记录" year = path4.split('ConserveRecord\\'); newyear = year[1].split('\\'); Url = year[1].replace(/\\/g, "/"); serverUrl = `${fileaddres.fileserver}` + "ConserveRecord/" + Url + "/" + file5Name; } let timeArr = file5Name.split('月'); let month = timeArr[0]; let day = timeArr[1].split('日')[0]; if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } let DateTime = newyear[0] + "-" + month + "-" + day; let sql = `insert into t_trafficpdf("name","date","serverurl","type") values ('${name}','${DateTime}','${serverUrl}','${type}') ` pool.query(sql, (err, ress) => { if (!err) { } else { console.log(err); } }) }) }) }) })