如何使用Node.js批量轉換檔案名稱

我有一個需求,需要將我的資料夾結構從這樣的樣式轉換為這樣的樣式: posts/test/index.md posts/hey-cool-post/index.md 變成: posts/test.md posts/hey-cool-post.md 刪除包含 index.md 文件的資料夾,而是將檔案本身設置為文章標籤(也就是用於文章網址)。 我使用了一個Node.js腳本來實現這個目的。 腳本如下: const fs = require('fs') const glob = require('glob') const root_folder = '.' //在當前資料夾中搜索 glob(root_folder + '/**/index.md', (err, files) => { if (err) { console.log('錯誤', err) } else { for (const file_path of files) { const match = file_path.match(/\/(.*?)\//) const folder_name = match[1] fs.copyFile(file_path, './' + folder_name + '.md', (err) => { if (err) { console.log('出現錯誤:', err) } else { console....