From 7649b7b40a259f46019d9bec79554272bd7bbe12 Mon Sep 17 00:00:00 2001 From: lichaojun Date: Wed, 25 Sep 2024 02:24:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8C=87=E5=AE=9A=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=EF=BC=8C=E6=89=B9=E9=87=8F=E8=A3=81=E5=89=AA=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E5=88=9B=E5=BB=BA=E7=9A=84=E5=AD=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E5=86=85=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5a5f4dd..1e7d676 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const path = require('path'); // 常见图片格式 const imageExtensions = new Set(['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'svg']); //图片文件夹路径 -const inputDir = 'H:/商品资料/ppt1032-国庆假期出游安全'; +let inputDir = ''; //输出比例 const outputArr = [ { @@ -19,6 +19,37 @@ const outputArr = [ dir: '', }, ]; +// 指定要查找的目录 +const directoryPath = 'E:/商品资料'; + +// 函数获取最新创建的子文件夹路径 +function getLatestFolder(directory) { + let latestTime = 0; + + // 读取指定目录 + fs.readdirSync(directory, { withFileTypes: true }).forEach((file) => { + if (file.isDirectory()) { + const folderPath = path.join(directory, file.name); + const stats = fs.statSync(folderPath); + const creationTime = stats.birthtimeMs; // 获取创建时间 + + // 找到最新创建的文件夹 + if (creationTime > latestTime) { + latestTime = creationTime; + inputDir = folderPath; + } + } + }); + + if (inputDir) { + console.log('最新创建的文件夹路径:', inputDir); + } else { + console.log('没有找到子文件夹。'); + } +} + +// 调用函数 +getLatestFolder(directoryPath); //创建输出文件夹 outputArr.forEach((item) => {