How to Bulk Convert File Names using Node.js
If you find yourself in a situation where you need to convert a folder structure like this:
posts/test/index.md
posts/hey-cool-post/index.md
into this:
posts/test.md
posts/hey-cool-post.md
where the folder containing an index.md
file is removed, and the post slug is used as the file name, you can accomplish this using a Node.js script. Below is an example script:
1 | const fs = require('fs'); |
By running this script, it will recursively search for all index.md
files in the specified rootFolder
, extract the parent folder name (post slug), and then copy the file to the new location using the post slug as the filename.
Tags: Node.js, file management, folder structure, file conversion