可以使用Node.js的fs模块进行遍历和修改文件名,以下是一个简单的示例代码:

const fs = require('fs');
const path = require('path');

const prefix = 'prefix_'; // 前缀

function addPrefixToFiles(dir) {
  // 遍历文件夹
  fs.readdir(dir, (err, files) => {
    if (err) throw err;
    files.forEach(file => {
      const filePath = path.join(dir, file);
      const stats = fs.statSync(filePath);
      if (stats.isFile()) { // 如果是文件
        // 修改文件名
        const newFilePath = path.join(dir, prefix + file);
        fs.renameSync(filePath, newFilePath);
      } else if (stats.isDirectory()) { // 如果是文件夹
        // 递归遍历
        addPrefixToFiles(filePath);
      }
    });
  });
}

// 调用示例
addPrefixToFiles('path/to/bundle');

该代码会递归遍历指定文件夹下的所有文件和子文件夹,并将文件名添加指定前缀。注意,修改文件名可能会对项目产生影响,请谨慎操作。建议先备份文件夹再进行修改。

cocos 批量给bundle下文件以及子文件添加前缀

原文地址: https://www.cveoy.top/t/topic/b2A1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录