How to rename all md files to mdx
Recently I converted my Gatsby blog from Markdown to MDX, and I wanted to convert all my .md
files over to .mdx
for consistency’s sake.
The folder structure of my repository looks something like this:
Since I have over 50 posts, I didn’t want to do the renaming manually!
If you’re using VSCode, there is a Batch Rename extension you can use. However, it doesn’t seem to work when all your files are located inside of their own folders (like mine are).
I came across this snippet:
This seems to do the trick for any files that live in the same folder.
To get all files that live underneath the posts
directory, this works:
The solution
Putting both of the above snippets together, I came up with this:
Before running the script, I would recommend checking that the
find
command is finding all the files you expect it to. Also, make sure to stash any other changes on your repository so that you can easily reverse this operation if it goes wrong!