灏天阁

NODEJS[14]:fs模块_批量重命名

· Yin灏
const files = fs.readdirSync("./code");
files.forEach((item) => {
  let data = item.split("-");
  let [num, name] = data;
  if (Number(num) < 10) {
    num = "0" + num;
  }
  let newName = num + "-" + name;
  fs.renameSync(`./code/${item}`, `./code/${newName}`);
});

- Book Lists -