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

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

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:
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.
You highlight the files in the explorer, right-click, and select Batch Rename
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
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

brew install rename
rename s/foo/bar/g **/*

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.
Open "everything" and filter the file list.
Select the files you want to change
pick "Change Name" with rButtom
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

Renaming multiple files with a single shot is also called batch renaming.
This can't be done from within Visual Studio Code.
There are two ways to get what you want:
(A) Rename files one by one
Go to the Explorer view in VS Code's Side Bar.
Select a file you want to rename.
Press F2 or choose Rename from that file's context menu.
Continue with step 2 as long as there are files you want to process.
(B) Batch rename multiple files using other tools
Go to the Explorer view in VS Code's Side Bar.
Select a file you want to rename.
Press Alt+Ctrl+R or choose Open Containing Folder from that file's context menu.
This brings up the file explorer of your operating system.
Batch rename the files from there. How this is done in detail is beyond the scope of this answer (most of the time, it is just selecting all files to process and starting the rename-tool).

Perhaps the easiest more detailed way is by using VSCode Terminal tab (Ctrl/Cmd + J) and selecting from the dropdown menu the Powershell option:
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.

You can rename a statement "in all files" highlighting it and then pressing "CTRL+R" and "CTRL+R"(again). That will replace the selected word/statement in the entire file and (if you don't disable the tooltip checkbox) in all other files where it matches.
I'm not sure if this answer your question, because this is for the text inside the files, not for the filenames.

Related

Automate find/replace in .md files in VS code [duplicate]

I was wondering if there was any way to repalce multiple line in multiple files at the same time?
I know under edit->Find in Files
this will show all the desires lines in all the files, however you have to raeplce them one by one, anyone way to just like REPLACE ALL?
Open the folder containing the files wished to be edited via Visual
Studio Code. If not exist, create a folder and fill up it with the files.
At the top-menu bar Edit - Replace in Files or (On Windows Ctrl + ⇧ + H, On Mac, ⌘ + ⇧ + H).
You can also Search and Replace across files. Expand the Search widget to display the Replace text box.
When you type text into the Replace text box, you will see a diff display of the pending changes. You can replace across all files from the Replace text box, replace all in one file or replace a single change.
https://code.visualstudio.com/Docs/editor/codebasics#_search-across-files
At the current time this is not supported (read in the link at Common Questions)
https://code.visualstudio.com/Docs/editor/codebasics#_common-questions
I suggest you to try with Notepad++
Replace in multiple files is supported in latest version of vscode 1.3.

Rename file with the information available in it

Issue - I have this large batch of pdf, word & notepad files which are required to be renamed according to the text available in each file.
For eg: I have to open file A, search the entire document for the string which will be used as its name, copy, close the file and rename the file.
After searching for some while I found that autohotkey can help me with this though I'm open to every solution. What I want to do is open the file, search for the name, select the text and use the keystroke to close and rename the file.
Could anyone help me with this?
I'm not going to give you a script but what you want can be done.
You need to collect various pieces of information when you rename a file. One of them being the current file name which you can often grab from the window title. You can use https://autohotkey.com/docs/commands/WinGetTitle.htm
If a filename is wrapped in [ ] you can remove those using https://autohotkey.com/docs/commands/StringReplace.htm
If you know the file path (folder where the file resides in) you can now use https://autohotkey.com/docs/commands/FileMove.htm to rename a file and use https://autohotkey.com/docs/misc/Clipboard.htm as a variable.
You would probably like to retain the extension (.doc, .txt, .pdf) so you can use https://autohotkey.com/docs/commands/SplitPath.htm to grab it and append that to the clipboard when you rename it.
Closing a file depends on your program, sometimes you can send ctrl+w or ctrl+w or you need to use the WinClose command so you need to add in that step before you use FileMove.

How to find folder in VS Code?

I have a project with a lot of files and folders. There are no problems with finding files. They can be found with Ctrl-P. But there are many folders in which files with the same name are made. Therefore, it is easier to search for a file by the name of the folder in which it is located. How in VS Code to search for folders in the current open project?
For example, I have the following project structure:
A/
main.js
B/
main.js
...
Z/
main.js
The file main.js from the folder P will be easier to find by the folder name.
While using Ctrl-P, you can type the full path of the file, so if i have two files named bar you can search on Ctrl-P with
"foo/bar" or with "qux/bar"
Vscode uses fuzzy search (like so many others), so you don't have to actually type the whole thing.
There is no way, to my knowledge and research, to find and be directed to a specific directory.
You can simply select a folder on the explorer and tape some filter keywords.
Recently, vscode added a shortcut, if you are using a recent release just typing won't work, first tape ctrl + f.
Ctrl + Shift + E
and start typing. You'll see your search on the top right corner of file explorer.
By default it does not filter by result but your focus will jumps to the first one. From there you can Enter to open it.
If you want to show only results containing the string of search : click on filter icon next to your search (state will be remembered).
Echap
to exit/remove search
or
Ctrl + Shift + E
again to switch back focus to last place you were typing.
This VSCode extension does exactly what you're asking for.
https://marketplace.visualstudio.com/items?itemName=rwu823.open-folder
I found a way to search through subfolders. Click on a folder you wish to search, than / and start typing for a name of subfolder
It's simple. Just open the parent folder of your folder in VSCode. Then right-click on the folder you want to find subfolder in and choose "Find in folder"

Merging two files in Notepad

Hi i have two long files both 30k lines long. Is there any way of merging them like that in Notepad++ or using other software?
1st line from 1st file: 1st line from second file
If you happen to have python on your computer, using itertools you can merge both files. Keep in mind that if one file ends before the other, whichever file keeps going will continue to put their lines into the output file.
from itertoools import izip
with open("outputfile.txt", 'w') as output:
with open ("firstfile.txt") as f1 , with open ("secondfile.txt") as f2:
for file1,file2 in zip(f1,f2):
output.write(f1)
output.write(f2)
For decades there have existed a command to do exactly this, paste. Example:
$ cat > file1
one
two
three
$ cat > file2
1
2
3
$ paste file1 file2
one 1
two 2
three 3
$
The free gnu version is currently part of coreutils, which I think is simplest to install via cygwin. If you need the separator to be exactly colon+space you can just pipe paste's output through sed 's/\t/: /'.
Here is a possible solution using Excel:
1.)
Open the first file with Excel (all the text should be in one column)
2.)
Open the second file with Excel (all the text should be in one column)
3.)
Go back to your first file and add a : to every row of the second column
4.)
Copy the first column of the second file and paste it to the third row of the first file
5.)
Save the combined file as *.txt file
this is not possible in Notepad as far as i know, so your best bet is Notepad++. is there a reason why you don't wanna use Notepad++?
EDIT: I see, i deserve that -rep :P sorry for not reading correctly.
What you do in Notepad++ is:
1. open Notepad++ and navigate to Plugins > Plugin Manager > Show Plugin Manager
2. look for and Check "Compare"
3. click "Install"
now what you do is you open your first file in Notepad++. after that, you open your second files inside the same window of Notepad++ and drag the second file to the middle of Notepad++ (so click and drag the second document to the middle of Notepad++) once you release, it will ask you what to do. Click on "Move next to eachother"
after you have done that, you can now click Plugin > Compare > Compare. this will comapre the 2 files and give you exactly whats different between them.
Sorry for putting the answer quickly without reading more carefully.

How to change Excel 2013 Template Miniature

Is there a simple way to change / replace the automatically generated Template Miniature with a different image.
I have checked this out for Excel 2016 but the process is similar.
First, the thumbnail is generated and part of the file. There is no official process. A description for brave Office pros is shown below.
You can do this:
First, close Excel!
Get to the location of your template
Make a copy
Rename the file extension to .zip
Unzip the file into a new folder using the Windows Zip utility
Search the tree of files for a file called thumbnail.wmf
Open PowerPoint and create an empty presentation
Use the function "Insert an Image" and add the thumbnail.wmf to the slide
Remove everything else from the slide
Try to ungroup - it fails with a message asking to convert to a drawing object
From here you have two options. Either convert, ungroup, change and proceed or throw away and create a new image from scratch.
Work on image and group your image (the old or a new one), then
Right click on the grouped image and click "Save as picture"
Choose the filetype "wmf" and name it the same as before and overwrite the existing thumbnail.wmf
Go INTO the folder using Windows Explorer of unpacked files, hit Ctrl-A (Select All)
Right click and say "Send to" --> "Compressed (zipped) folder". Give it a new name.
Hit F2 to rename the file
Remove the file extension .zip
Now, open Excel!
Hit "New", "Personal" and you see your template with your custom image in full width and height. Repeat steps 10 to 16 until you're satisfied.
Drawbacks: Once you edit your file in excel and save as template with thumbnails option (advanced properties) switched on, Excel will overwrite your custom wmf-file. You have to repeat the steps "Unpack -> Replace File -> Pack" every time.
I'll post an update once I found a better solution.
Here is an automation of the process that might help with understanding the process described in the answer.
Python 3 code snippet
import zipfile
import shutil
exfilename = 'MYTEMPLATE.xltm'
a_path='C:\\TEMP'
th_path='mythumbnail.wmf'
with zipfile.ZipFile (exfilename, 'r') as zf:
#Extract to temporary folder
zf.extractall(a_path)
#replace the thumbnail
shutil.copyfile(th_path,a_path+'\\docProps\\thumbnail.wmf')
#remake the zip as a new file
shutil.make_archive('TEMP_ARCHIVE','zip',a_path)
#rename back to original, replacing original
shutil.move('TEMP_ARCHIVE.zip',exfilename)
#clean-up temporary files
shutil.rmtree(a_path)