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