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
相关推荐
持敬chijing1 小时前
PHP开发-环境搭建-安装phpstudy-vscode工具
开发语言·vscode·php
csdn_aspnet2 小时前
Copilot能换成本地吗?VSCode接本地大模型本地化接入方案
ide·vscode·ai·ollama
青 春 记 忆4 小时前
零基础入门python04:用注册校验理解字典、集合和条件判断
开发语言·vscode·python·python3.11
00后程序员张8 小时前
有没有更轻量的 iOS 开发环境?快蝎kxapp轻量化路径与构成
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
buhuizhiyuci9 小时前
【Linux 网络篇】数据的 “循环系统“:协议认识与网络传输的流程
linux·运维·服务器·网络·vscode
猿小猴子1 天前
主流 Agent 之 「Zed」和 「ZCode」 介绍
ide·ai·agent·zed·zhipu·ade·zcode
ue星空1 天前
【Godot】更换编辑器外观主题
编辑器·游戏引擎·godot
没事学点编程小知识1 天前
免费的在线EPUB编辑器:E-Ink
编辑器
浪客川1 天前
使用 IDEA 生成API文档
java·ide·intellij-idea
SMF19191 天前
【PyCharm】让 PyCharm 使用 .venv 虚拟环境
ide·python·pycharm