How to rename files in VS Code in bulk?

Viewed 3433

Is there a way to search for ALL .txt files in a project and automatically replace/rename them to .js?

E.g user.txt to user.js

It seems I can't search for a file format in VS Code.
If you know how, please share!

4 Answers

You could just do it in the terminal.

mv *.txt *.js

You can use a combination of:

For example, given these files/folders:

VS Code screenshot of initial file/folders

Steps:

  1. Start by clicking on the EXPLORER panel and filtering to just display .txt files

    VS Code screenshot with filtered .txt files

  2. Select/highlight all the files, then right-click on any selected file, then select "Batch Rename"

    VS Code screenshot of context menu with "Batch Rename" highlighted

  3. That would open a text file ".Batch Rename.txt" with all the selected files

    VS Code screenshot with Batch Rename.txt

  4. Do a regular find-and-replace to change .txt to .js

    VS Code screenshot with Batch Rename.txt with .txt changed to .js

  5. Note that the ".Batch Rename.txt" is unsaved. It's like a preview of what the changes would look like

  6. Save ".Batch Rename.txt" and it will automatically close

  7. The EXPLORER panel should now be empty since it's filtered on .txt

    VS Code screenshot with empty EXPLORER panel

  8. Remove the filter and the files should now be renamed

    VS Code screenshot with .txt changed to .js

Old question, I know, but for you or anyone else coming in, if you're okay with using a non-VS Code solution, there's a GUI Windows tool called RegexRenamer that is so well-named, you already know what it does.

It gives you a preview of what the renamed files will look like, and has options to rename everything in subfolders or only the current folder, ignore/include file extensions in the search, and apply the rename only to folders/files or both.

What do you think?

Related