-1

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!

Gino Mempin
  • 19,150
  • 23
  • 79
  • 104
Rene
  • 35
  • 1
  • 3
  • 1
    Why do you need to do this using vscode? – ThisaruG Mar 28 '20 at 20:47
  • Does this answer your question? [Recursively change file extensions in Bash](https://stackoverflow.com/questions/21985492/recursively-change-file-extensions-in-bash) – ThisaruG Mar 28 '20 at 20:51
  • Try using powershell from terminal – JWP Mar 28 '20 at 21:01
  • "*I can't search for a file format in VS Code*": You can use the main Search panel (the magnifying glass), use a space for the search pattern, and use `*.txt` for files to include. That will list all *.txt files (with a space). – Gino Mempin Mar 29 '20 at 14:19

3 Answers3

3

VS Code does not have a built-in way of renaming multiple files.

But there is an extension that can help you do this.
See vsc-rename-files.

Let's say we have this folder and files:

enter image description here

  1. Right-click on the folder and select "Rename files".
  2. Select "Rename with String" enter image description here
  3. Select either in selected folder only or in all sub-folders enter image description here
  4. Specify the from string enter image description here
  5. Specify the to string enter image description here

The result:

enter image description here


As for your other question:

It seems I can't search for a file format in VS Code.

As I mentioned in the comments, you could search for a space (" ") then specify only to include the files of a specific extension (ex. /path/to/folder/*.js). That would find all non-empty files with a space.

enter image description here

Gino Mempin
  • 19,150
  • 23
  • 79
  • 104
1

You could just do it in the terminal.

mv *.txt *.js
Paul Fitzgerald
  • 10,773
  • 3
  • 38
  • 53
0

You can use find to do this in a terminal recursively.

find . -iname "*.txt" -exec rename .txt .js '{}' \;

refer Find multiple files and rename them in Linux

mv works if you want to just do it in a folder itself.

Gautham Santhosh
  • 717
  • 1
  • 8
  • 19