How to rename multiple files in vscode (visual studio code)?

Viewed 88698

I wonder, if there is way to rename multiple files in visual studio code? I have tried to use find and replace, no luck.

10 Answers

Here is how you can do it on Mac. Right-click (or ctrl+click or click with two fingers simultaneously on the trackpad if you are using a MacBook) on the folder that contains the files that you want to have renamed. Then click Reveal In Finder. Then from within finder select all files you want to rename, right-click the selected files and choose Rename X items.... Then you will see something like this:

enter image description here

Insert the string you want to find and the string with which you want to replace that found string and hit rename. Done

There are a few Visual Studio Extensions that try to provide this functionality. The first two I tried did not appear to work. There is an extension called Batch Rename which worked for me: https://marketplace.visualstudio.com/items?itemName=JannisX11.batch-rename-extension.

Here is how the extension works.

  1. You highlight the files in the explorer, right-click, and select Batch Rename
  2. The extension creates a text file with the names of the files you want to rename, one each line. Update the text file with the new names
  3. Save the temporary text file from step 2 and the extension performs the rename.

VS Code only supports single file name. On Windows, to do batch rename, you can use one of the following

[CMD]

// Change the extensions of all .doc files to .txt
ren *.doc *.txt

// Replace the first three characters of all files starting with 'abc' by 'xyz'
ren abc* xyz*


[PowerShell]
Get-ChildItem *.txt | Rename-Item -NewName { $_.Name.Replace('.txt','.log') }

A comprehensive tutorial can be found here

Not an option for Visual Studio Code (yet)...

...but in Sublime Text with the dired package you can enter rename mode with Shift + R.
This gives you a buffer with each file on its line:

D:\path\to\myfolder

first.file
second.file
third.file
...
umpteenth.file

 Rename files by editing them directly, then:
 Ctrl+Enter = apply changes
 Ctrl+Escape = discard changes

While in rename mode you can use the full power of the text editor: edit all filenames at once with multiple cursors, transpose strings (to accomplish switch renames in one fell swoop), find and replace, the Text Pastry package can give you number ranges etc.

vscode-dired will not let you do this, renames are one by one.

You can not rename several files at the same time in vscode,. The simplest way I found is using the free "everything" utility, it takes seconds to rename a bunch of files in one or several folders.

  1. Open "everything" and filter the file list.
  2. Select the files you want to change
  3. pick "Change Name" with rButtom
  4. Popup will display with old list, the new list, the old names and the new names, if you change the new name, the new list will change accordingly.

VS Code has no such type of facility yet or extension on it. But using vs code terminal as a cmd and run this command on the folder where you want to change all file names from one to another like I want to change my all view files from HTML to PHP.

rename *.html *.php

Perhaps the easiest more detailed way is by using VSCode Terminal tab (Ctrl/Cmd + J) and selecting from the dropdown menu the Powershell option:

Terminal/shell options

Based on Kin's answer and the resource Kin provided (2nd page), in order to look into the current and all sub-folders, these are some useful renaming possibilities:

Extensions rename

ls -R *.txt | Rename-Item -NewName {[io.path]::ChangeExtension($_.name, "log")}

Selects txt files and renames their extensions to log.

Name+extension rename

Get-ChildItem -R *.txt | Rename-Item -NewName {$_.name.Replace('.txt','-text.log')}

Selects txt files and renames them to [ORIGINAL_NAME]-text.log.

NEW_NAME+NUMBER+extension rename (original names are discarded)

Get-ChildItem -R *.txt | %{Rename-Item $_ -NewName ("NEW_NAME-{0}.log" -f $nr++)}

Selects txt files and renames them to [NEW_NAME]-NUMBER.log.

How it works:

  • ls, an alias of the Get-ChildItem command (equivalent in Powershell), lists current directory files;
  • -R option allows the recursive lookup to happen;
  • listing result is piped into a multiple Rename-Item commands invocation.
Related