vscode过滤文件

js 复制代码
const fs = require('fs');
const { exec } = require('child_process');

// ========== 在这里输入你的关键词,每行一个 ==========
const keywordsStr = `
BV1wmXwBCEsZ
BV1MR6wBREhY
BV1DuoSYuEpX
`;
// =================================================

// 将多行字符串按换行符分割,过滤掉空行
const keywords = keywordsStr.trim().split(/\r?\n/);

if (keywords.length === 0) {
  console.error('没有提供任何关键词');
  process.exit(1);
}

console.log(`使用 ${keywords.length} 个关键词:`, keywords);

// 读取当前目录下的所有文件
const files = fs.readdirSync('./');

// 筛选出文件名中包含至少一个关键词的文件
const matched = files.filter(file => 
  keywords.some(kw => file.includes(kw))
);

if (matched.length === 0) {
  console.log('没有匹配到任何文件');
  process.exit(0);
}

console.log('匹配到的文件:');
matched.forEach(f => console.log(f));

// 自动在 VSCode 中打开所有匹配的文件
matched.forEach(file => {
  exec(`code "${file}"`, (err) => {
    if (err) console.error(`打开 ${file} 失败:`, err.message);
  });
});

console.log(`\n正在打开 ${matched.length} 个文件...`);

运行命令

xml 复制代码
node filter.js
相关推荐
2501_9159090620 小时前
移动端开发工具链怎么组合比较好,iOS、Android、跨端三套配置方案
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
weixin_4640780720 小时前
ppt转为draw.io方法
编辑器
sunoo-22921 小时前
【ARM嵌入式学习笔记Day6】一文打通i.MX6ULL时钟体系:PLL/PFD/预分频+滞回比较器全解析
arm开发·笔记·vscode·单片机·imx6ull·汇编语言
明天…ling21 小时前
gitee与vscode远程连接
vscode·gitee
2501_915918411 天前
iOS编程用什么软件好?主流工具Xcode、AppCode、CodeRunner与新兴快蝎对比
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
__pop_2 天前
VSCode Remote SSH 远程连接 glibc 高版本依赖问题
vscode
daxiangxm2 天前
【趣味休息】“围住小猫在线玩”-“困住小猫”,又回来了
数据结构·人工智能·vscode·github·php
星光开发者2 天前
基于Spring Boot的充电桩管理系统的设计与实现-计算机毕设【课程设计】57105
vue.js·spring boot·vscode·mysql·django·php·express
程序员允诺2 天前
内网/无网环境必备:VS Code Remote-SSH 离线包下载与手动部署教程
vscode
滕州市燕猫虎计算机科技工作室个体工商户2 天前
IDEA:Command line is too long
java·ide·intellij-idea