xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

How to fix macOS Finder not support semicolon symbol in filename error All In One

How to fix macOS Finder not support semicolon symbol in filename error All In One

macOS Finder 不支持文件名中包含 : 分号 bug ❌

error

  • semicolon / 分号
  • punctuation marks / 标点符号

The name “01 项目基石:前端脚手架工具探秘.mp4” can’t be used.
Try using a name with fewer characters, or with no punctuation marks.

solution

// import * as pfs from "node:fs/promises";
import fs from 'node:fs';
import path from 'node:path';

const __dirname = path.resolve();
// const __filename = fileURLToPath(import.meta.url);
// console.log(`__dirname`, __dirname);

const folder = path.join(__dirname, '前端工程化精讲');
const files = fs.readdirSync(folder);
// console.log(`files`, files);

for (const file of files) {
  // const filename = file.replaceAll(/(:)/g, ``).replace(/(/, `(`).replace(/)/, `)`).replace(`?`, ``);
  const filename = file
    .replace(/(\|\s)/g, ``)
    .replace(/:/g, `_`)
    // .replace(/:/g, `:`) // macOS Finder 不支持,文件名中包含 `:` 分号
    .replace(/:/g, `_`)
    .replace(/(/, `(`)
    .replace(/)/, `)`)
    .replace(/,/, `,`)
    .replace(/(“|”)/g, `"`)
    .replace(/、/g, `,`)
    .replace(/(\/)/g, `_`)
    .replace(`?`, ``);
  fs.renameSync(`${folder}/${file}`, `${folder}/${filename}`, (err) => {
      if(err) {
        console.error(`rename ❌`, err);
      }
      console.log(`rename ✅`)
    }
  )
}

demos

refs



©xgqfrms 2012-2025

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
历史上的今天:
2022-09-15 在线文档 All In One
2022-09-15 Apple iPhone 官方原装保护壳港版与国行版区别 All In One
2021-09-15 Redux & React Hooks All In One
2020-09-15 C++ 0LL
2020-09-15 从长度为 M 的无序数组中,找出N个最小的数 All In One
2019-09-15 elm & redux
2019-09-15 约定优于配置
点击右上角即可分享
微信分享提示