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
相关推荐
zhangfeng11331 天前
WebIDE 容器中 AtomCode 报 `ATOMCODE_SIG_STALE` 排查实录:一次由 8 小时时钟偏差引发的“悬案”
编辑器·ai编程·atomcode
witton1 天前
MacOS中在目录或者文件右键菜单中添加“使用VSCode打开”
vscode·macos·文件·目录·服务·automator·右键菜单
wabil2 天前
[AI-Talk] codx制作xmind文件技巧
ide·ai编程·myeclipse·xmind
大衛說2 天前
02 · 环境搭建:uv 包管理与现代 IDE
ide·uv
山峰哥2 天前
数据库工程与查询优化案例深度复盘‌
数据库·sql·oracle·编辑器·深度优先·宽度优先
cndes2 天前
安装Miniconda+Jupyter notebook
ide·python·jupyter
码上暴富2 天前
Cursor / VS Code 自定义文件颜色
前端·vscode
洛兮银儿2 天前
pycharm选中同一个词的标记颜色的修改
ide·python·pycharm
2601_962381582 天前
VSCode如何配置LlamaIndex RAG(检索增强生成)应用开发环境
vscode·开发环境·rag·llamaindex·检索增强生成
javgo.cn3 天前
Markweave:开源 Markdown-first WYSIWYG 编辑器
开源·编辑器