Eslint 校验报错异常,修改部分代码和文档格式 (#184)
const fs = require('node:fs')const path = require('node:path')/*** 递归遍历目录并重命名所有遇到的Readme.md文件为README.md*/function renameReadmeFiles(dirPath) {fs.readdir(dirPath, (err, files) => {if (err) {console.error(`Error reading directory: ${dirPath}`, err)return}files.forEach((file) => {const filePath = path.join(dirPath, file)fs.stat(filePath, (err, stats) => {if (err) {console.error(`Error getting stats for: ${filePath}`, err)return}if (stats.isDirectory()) {// 如果是目录,则递归调用renameReadmeFiles(filePath)}else if (file.toLowerCase() === 'readme.md') {// 如果是Readme.md文件,则重命名const newFilePath = path.join(dirPath, 'README.md')fs.rename(filePath, newFilePath, (err) => {if (err) {console.error(`Error renaming: ${filePath}`, err)}else {console.log(`Renamed: ${filePath} to ${newFilePath}`)}})}})})})}// 调用函数,传入你想要开始遍历的目录路径renameReadmeFiles('docs')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。