一键筛选不需要的.csv文件

1.下载node

2.创建.js文件

const fs = require("fs");

const path = require("path");

// 定义要保留的文件名数组

const fileNamesToKeep = [

 "文件1","文件2","文件3"

]; // 根据需要修改文件名

// 指定要检查的文件夹路径

const folderPath = "F:/故障"; // 替换为您的文件夹路径

// 读取文件夹内容

fs.readdir(folderPath, (err, files) => {

  if (err) {

    return console.error(`Unable to scan directory: ${err}`);

  }

  // 遍历文件夹中的所有文件

  files.forEach((file) => {

    const fullFilePath = path.join(folderPath, file);

    const shouldKeep = fileNamesToKeep.some((name) => file.includes(name));

    // 检查该文件是否应该保留

    if (!shouldKeep) {

      // 如果不在列表中,删除该文件

      fs.unlink(fullFilePath, (err) => {

        if (err) {

          console.error(`Error deleting file: ${fullFilePath}, ${err}`);

        } else {

          console.log(`Deleted: ${fullFilePath}`);

        }

      });

    } else {

      console.log(`Kept: ${fullFilePath}`);

    }

  });

});

3. const folderPath = "F:/故障"; // 替换为您的文件夹路径

4.运行,node .\监测.js   (.\监测.js)为js文件名称

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值