Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename files in VS Code in bulk?

Tags:

vs-code

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!

like image 467
Rene Avatar asked Oct 13 '26 13:10

Rene


2 Answers

You can use a combination of:

  • Filtering the EXPLORER panel to just show .txt files
    • See "Filtering the document tree" section of the VS Code docs
    • See related Stack Overflow post: "Filter files shown in Visual Studio Code"
  • Installing and using the Batch Rename extension

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

like image 75
Gino Mempin Avatar answered Oct 15 '26 02:10

Gino Mempin


You could just do it in the terminal.

mv *.txt *.js
like image 34
Paul Fitzgerald Avatar answered Oct 15 '26 04:10

Paul Fitzgerald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!