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
(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!