How to change encoding of all files at once with Jetbrains IDE like WebStorm
Asked Answered
S

5

12

For some unknown reason, the encoding of my files has changed without me noticing for a while.

It was UTF-8 and now is windows-1252. I have reset the project encoding from Settings->File encoding but I can't detect which files are badly encoded and can't figure out how to reencode all files within the project at once.

I have a strong feeling that the problem appeared with WebStorm 10 first released version, but I may be wrong. (I think it's because it set by default the project encoding setting to windows-1252)

Spotlight answered 4/4, 2015 at 21:35 Comment(1)
In the meantime I've opened a bug issue on their issues tracking website to get the problem looked into and ultimately fixed. youtrack.jetbrains.com/issue/WEB-16054Spotlight
U
12

Close every project you have opened by clicking File > Close Project.

Once they are all closed, the startup window will show up (The window with the latest opened projects with the options to open new project, etc..) In that window, at the bottom right corner you have settings.

In Settings > Editor > File Encodings.You can set up all the File Encoding options to UTF-8, it will be added to the new projects from now on.

If you want it for old projects, do the same steps, but access the settings once you have the project open.

I hope this help!

Usk answered 1/9, 2015 at 10:35 Comment(1)
If it helps, I had to restart the IDE after that configuration change.Sacrilegious
S
1

To convert the file encoding, you have to use some external tool to perform the conversion, such as iconv:

iconv -f windows-1252 -t utf-8 <input file> > <output file>
Sporozoite answered 2/5, 2018 at 13:9 Comment(0)
S
0

If you have encoding defined in your files e.g. like this <meta charset="windows-1252"> you can you use Idea's Replace in Path... functionality and modify multiple files at once.

Even you don't have that definition, you may be able to add it to your files using the same search and replace functionality. I had to convert massive amount of ISO-8859-1 encoded file to UTF-8 and this solution worked fine.

Spicy answered 21/8, 2017 at 7:43 Comment(0)
C
0

I used this powershell script, it works very well, just open a powershell in the directory of your project and copy paste this and execute, just change the *.java by the file type you use

Get-ChildItem -Recurse -Filter "*.java" | ForEach-Object {
  $content = Get-Content -Path $_.FullName
  $content | Out-File -FilePath $_.FullName -Encoding UTF8
}
Charlie answered 4/4, 2024 at 20:48 Comment(0)
C
-1

You can change your code's character set in WebStorm foot bar

  1. Open code file
  2. You can see foot bar ( This menu is in right down. )
  3. Click character set select bar
  4. change your code encoding
  5. change and save
Coaptation answered 27/7, 2015 at 11:30 Comment(1)
Yeah, it's a solution for a file-by-file basis. Not for all files at the same time. :)Spotlight

© 2022 - 2025 — McMap. All rights reserved.