This isn't really a programming question, is there a command line or Windows tool (Windows 7) to get the current encoding of a text file? Sure I can write a little C# app but I wanted to know if there is something already built in?
-
23**_Guess_ encoding of a file in Windows** is what the title should be. If you don't know in advance, you'll never be able to guess for certain. – Tom Blodget Mar 11 '16 at 00:57
-
1You can use a free utility called Encoding Recognizer (requires java). You can find it at http://mindprod.com/products2.html#ENCODINGRECOGNISER – Ville May 06 '11 at 20:52
-
2@TomBlodget Your comment makes sense. Then how do the below answers work? Are they just guessing? – starriet Jul 14 '22 at 11:56
14 Answers
Open up your file using regular old vanilla Notepad that comes with Windows 7.
It will show you the encoding of the file when you click "Save As...".
It'll look like this:
Whatever the default-selected encoding is, that is what your current encoding is for the file.
If it is UTF-8, you can change it to ANSI and click save to change the encoding (or visa-versa).
There are many different types of encodings, but this was all I needed when our export files were in UTF-8 and the 3rd party required ANSI. It was a onetime export, so Notepad fit the bill for me.
FYI: From my understanding I think "Unicode" (as listed in Notepad) is a misnomer for UTF-16.
More here on Notepad's "Unicode" option: Windows 7 - UTF-8 and Unicode
Update (06/14/2023):
Updated with screenshots of the newer Notepad and Notepad++
Notepad (Windows 10 & 11):
Bottom-Right Corner:
"Save As..." Dialog Box:
Notepad++:
Bottom-Right Corner:
"Encoding" Menu Item:
Far more Encoding options are available in NotePad++; should you need them.
Other (Mac/Linux/Win) Options:
I hear Windows 11 improved the performance of large 100+MB files to open much faster.
On the web I've read that Notepad++ is still the all around large-file editor champion.
However, (for those on Mac or Linux) here are some other contenders I found:
1). Sublime Text
2). Visual Studio Code

- 18,543
- 7
- 76
- 70
-
there is no notepad on windows 8 and editor (which seems to be the replacement) does not have this functionality – Alex Jul 20 '15 at 12:28
-
1@Alex, I do not use Win-8. Performing a google search, I found this link: [Win-8 Notepad](https://echlinm.wordpress.com/2011/11/06/windows-8-start-menu-where-did-notepad-go/). I hope you find it because I assure you, it's still there. – MikeTeeVee Jul 20 '15 at 15:48
-
1Thanks but on Windows 8.1 there is definitely no app called notepad. When you enter notepad in the search, "editor" appears. And this does not have that endoding dropdown and no menu for it either – Alex Jul 20 '15 at 19:50
-
4This method does not work for files that are too large for Notepad to open. And that limit is reached much faster than other editors like Notepad++. My Windows 8.1 does have Notepad. Look in %windir%\system32\notepad.exe maybe? – Fabian Kessler Aug 04 '16 at 17:16
-
Notepad, as distributed with Windows systems, will crash on files over 64k. If I were to trust the encoding listed in "Save as", then I'll need to trust that this 64.1k file is completely blank. Unreliable. Just look at that list in your image example: it doesn't even list the only encoding that Windows uses as default, CP1252!!! So unreliable. – HoldOffHunger Sep 01 '16 at 15:03
-
3
-
Read this article if you are curious about all these: https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ – Darkgaze Apr 12 '17 at 08:42
-
11Notepad is installed in ALL versions of Windows since Windows 3 at least. – Jean-François Larvoire Apr 13 '17 at 14:39
-
In windows 10, its shortcut is in "Windows Accessories". To avoid searching for the shortcut, simply press Windows+R then type notepad. And Notepad definitely works on files of all sizes, albeit slowly on files larger than 100MB. I've used it today to review 3MB log files. – Jean-François Larvoire Apr 13 '17 at 14:45
-
I just used this to identify encoding on a 7MB text file in Windows 8.1. This is a good solution and the drawbacks mentioned in comments don't seem to apply in the real world. – Robin French Jun 29 '17 at 14:04
-
@HoldOffHunger Notepad is not for big files usage, but it does have the ability to open files larger than 64KB at least since XP. Only the version in Windows 98 and previous support a maximum of 64KB – phuclv May 14 '18 at 17:01
-
1One option is to download Notepad++. It is a very powerful free notepad and works as it was explained by @MikeTeeVee – Colibri Feb 26 '19 at 03:11
-
Anyone knows how does Notepad's "ANSI" encoding map to CRAN's R read_delim() function encoding types? – cineS. Jul 29 '21 at 12:48
-
1
If you have "git" or "Cygwin" on your Windows Machine, then go to the folder where your file is present and execute the command:
file *
This will give you the encoding details of all the files in that folder.

- 1,997
- 2
- 13
- 8
-
1adding to your answer, If you only interested in specific file, you can use [grep command](https://phoenixnap.com/kb/grep-command-linux-unix-examples) to filter the results of `file *` command – ebram khalil Aug 30 '19 at 12:57
-
10Instead of just blindly running file command, the full command that answers this question is `file --mime-encoding` to get the encoding for the file – smac89 May 06 '20 at 03:57
-
6In 2020, the question is not cygwin anymore, it is wsl or wsl2. Cygwin is nearly dead. – Timo Oct 25 '20 at 19:11
-
3In 2021, this works in git-bash (aka the shell that ships with "Git for Windows"). It uses MinGW, not Cygwin. – user2864740 Sep 10 '21 at 01:56
The (Linux) command-line tool 'file' is available on Windows via GnuWin32:
http://gnuwin32.sourceforge.net/packages/file.htm
If you have git installed, it's located in C:\Program Files\git\usr\bin.
Example:
C:\Users\SH\Downloads\SquareRoot>file * _UpgradeReport_Files; directory Debug; directory duration.h; ASCII C++ program text, with CRLF line terminators ipch; directory main.cpp; ASCII C program text, with CRLF line terminators Precision.txt; ASCII text, with CRLF line terminators Release; directory Speed.txt; ASCII text, with CRLF line terminators SquareRoot.sdf; data SquareRoot.sln; UTF-8 Unicode (with BOM) text, with CRLF line terminators SquareRoot.sln.docstates.suo; PCX ver. 2.5 image data SquareRoot.suo; CDF V2 Document, corrupt: Cannot read summary info SquareRoot.vcproj; XML document text SquareRoot.vcxproj; XML document text SquareRoot.vcxproj.filters; XML document text SquareRoot.vcxproj.user; XML document text squarerootmethods.h; ASCII C program text, with CRLF line terminators UpgradeLog.XML; XML document text C:\Users\SH\Downloads\SquareRoot>file --mime-encoding * _UpgradeReport_Files; binary Debug; binary duration.h; us-ascii ipch; binary main.cpp; us-ascii Precision.txt; us-ascii Release; binary Speed.txt; us-ascii SquareRoot.sdf; binary SquareRoot.sln; utf-8 SquareRoot.sln.docstates.suo; binary SquareRoot.suo; CDF V2 Document, corrupt: Cannot read summary infobinary SquareRoot.vcproj; us-ascii SquareRoot.vcxproj; utf-8 SquareRoot.vcxproj.filters; utf-8 SquareRoot.vcxproj.user; utf-8 squarerootmethods.h; us-ascii UpgradeLog.XML; us-ascii
-
1note that you probably need git 2.x for it, I don't have it with git 1.9.5 – jakub.g Aug 31 '16 at 14:47
-
-
1Unbelievable to have to revert to command line for basic operation, this is 2017, but it looks to do ok. – Todd Partridge Sep 18 '17 at 16:47
-
1Like [the other answer](https://stackoverflow.com/a/43489411/393280) says, you can also use the `file` command in **cygwin**. Any POSIX toolset for Windows should have `file`. – palswim Feb 23 '18 at 22:38
-
If you installed git for windows, it includes GIT BASH (bash emulator), which in turn includes the 'file' command. Just used it and it works. It's mentioned also in the next answer... – Amir Katz Oct 04 '18 at 11:00
-
-
Install git ( on Windows you have to use git bash console). Type:
file --mime-encoding *
for all files in the current directory , or
file --mime-encoding */*
for the files in all subdirectories

- 23,523
- 27
- 108
- 164

- 419
- 4
- 3
-
-
1Nice answer. However, `file --mime-encoding */*` will miss all files in `*/*/*`. So you also need to run `file --mime-encoding */*/*`, and so on, if you want to catch *all* files in the whole subdirectory tree. – Henke Mar 12 '23 at 13:11
Another tool that I found useful: https://archive.codeplex.com/?p=encodingchecker EXE can be found here

- 3,214
- 2
- 17
- 24
-
4
-
1Instant answer even with very large files (as one would expect). – Fabian Kessler Aug 04 '16 at 17:24
-
1
-
2can't figure out where the exe file is on that page. Is the link outdated? – Christoph Oct 21 '18 at 21:47
-
-
@MarkDeven Yeah. there is no EXE but if you have visual studio you can compile SLN file to create EXE. let me know if that doesn't work for you – user961954 Jan 17 '19 at 18:14
-
1
-
2[https://github.com/amrali-eg/EncodingChecker](https://github.com/amrali-eg/EncodingChecker) there is a modified version. – Jarvars Apr 23 '21 at 13:33
-
Here's my take how to detect the Unicode family of text encodings via BOM. The accuracy of this method is low, as this method only works on text files (specifically Unicode files), and defaults to ascii
when no BOM is present (like most text editors, the default would be UTF8
if you want to match the HTTP/web ecosystem).
Update 2018: I no longer recommend this method. I recommend using file.exe from GIT or *nix tools as recommended by @Sybren, and I show how to do that via PowerShell in a later answer.
# from https://gist.github.com/zommarin/1480974
function Get-FileEncoding($Path) {
$bytes = [byte[]](Get-Content $Path -Encoding byte -ReadCount 4 -TotalCount 4)
if(!$bytes) { return 'utf8' }
switch -regex ('{0:x2}{1:x2}{2:x2}{3:x2}' -f $bytes[0],$bytes[1],$bytes[2],$bytes[3]) {
'^efbbbf' { return 'utf8' }
'^2b2f76' { return 'utf7' }
'^fffe' { return 'unicode' }
'^feff' { return 'bigendianunicode' }
'^0000feff' { return 'utf32' }
default { return 'ascii' }
}
}
dir ~\Documents\WindowsPowershell -File |
select Name,@{Name='Encoding';Expression={Get-FileEncoding $_.FullName}} |
ft -AutoSize
Recommendation: This can work reasonably well if the dir
, ls
, or Get-ChildItem
only checks known text files, and when you're only looking for "bad encodings" from a known list of tools. (i.e. SQL Management Studio defaults to UTF16, which broke GIT auto-cr-lf for Windows, which was the default for many years.)

- 4,224
- 3
- 39
- 57
-
There are *many* variations of `Get-FileEncoding` on poshcode. I've even reviewed punycode from python and nodejs, but this small version hits 80/20 for my usage (more like 99/1). If you're hosting other people's files I suggest you use `file` command from Syben's answer (https://stackoverflow.com/a/34766140/195755) or another production-quality unicode decoder. – yzorg May 27 '17 at 17:28
-
It should be added that this method works only if the BOM is present... which is not always the case – Yepeekai Feb 16 '18 at 20:34
-
@Yepeekai The last line is `default` encoding (when no BOM). For XML, JSON, and JavaScript the default is UTF8, but your mileage may vary. – yzorg Feb 20 '18 at 14:35
-
@yzorg: but that's a brain dead way to do it. You're just lying to the user. At least most parsers make an educated guess. If you can't make a guess just throw an error and tell them a BOM is required to use your code (and then go use another, smarter tool as many already exist). – Ed S. Jun 04 '18 at 20:01
-
@EdS. Sure, but seems impossible to know for sure. I am the user when this code is run, so it is optimized for my use case (git hooks, or other scenarios where encodings break devops tools). – yzorg Jun 04 '18 at 20:37
-
Sure, it is impossible to know _for sure_, but you can make an educated guess via heuristics. I get that this is your code, but once it hits e.g. SO for public consumption it's open to criticism. – Ed S. Jun 06 '18 at 19:03
-
1@EdS. It's said in answer #2 and in comments of answer #1 that if you're looking for an "authoritative" encoding or file type to use `file.exe` from cygwin or GIT tools. I also mention it in my response to other comments. I follow that advice, see a later answer (also by me) https://stackoverflow.com/a/46816054/195755 for tips on using `file.exe` from powershell. Would you like me to include that qualifier in the body of my answer? – yzorg Jun 07 '18 at 15:25
-
@yzorg: That's fine, but this is your answer. I commented on this, your answer, which says none of that. You're saying I need to go read other answers and your comments elsewhere to better understand your own? – Ed S. Jun 13 '18 at 21:27
A simple solution might be opening the file in Firefox.
- Drag and drop the file into firefox
- Press Ctrl+I to open the page info
and the text encoding will appear on the "Page Info" window.
Note: If the file is not in txt format, just rename it to txt and try again.
P.S. For more info see this article.

- 10,860
- 6
- 57
- 75
-
2Looks like `View Page Info` is no longer around per [Firefox 88 has quietly removed these features](https://winaero.com/firefox-88-has-quietly-removed-these-features/) from April 2021. CTRL-I (Windows OS on Jan 2022) as a workaround – Intrastellar Explorer Jan 24 '22 at 23:48
I wrote the #4 answer (at time of writing). But lately I have git installed on all my computers, so now I use @Sybren's solution. Here is a new answer that makes that solution handy from powershell (without putting all of git/usr/bin in the PATH, which is too much clutter for me).
Add this to your profile.ps1
:
$global:gitbin = 'C:\Program Files\Git\usr\bin'
Set-Alias file.exe $gitbin\file.exe
And used like: file.exe --mime-encoding *
. You must include .exe in the command for PS alias to work.
But if you don't customize your PowerShell profile.ps1 I suggest you start with mine: https://gist.github.com/yzorg/8215221/8e38fd722a3dfc526bbe4668d1f3b08eb7c08be0
and save it to ~\Documents\WindowsPowerShell
. It's safe to use on a computer without git, but will write warnings when git is not found.
The .exe in the command is also how I use C:\WINDOWS\system32\where.exe
from powershell; and many other OS CLI commands that are "hidden by default" by powershell, *shrug*.

- 4,224
- 3
- 39
- 57
-
1or you could just use `file` as your alias to file.exe instead of `file.exe` ¯\\_(ツ)_/¯ – scrthq Aug 09 '18 at 23:13
-
@ferrell_io TL;DR: PS is based on .NET and .NET has File static class, and PS has enough confusing overloads with common EXEs that I use .exe to differentiate PS from Win EXE: `dir | where Size -lt 10000` vs `where.exe git`. – yzorg Feb 13 '19 at 15:16
-
@ferrell_io I use `where.exe` to differentiate it from `where` in PS, which is a built-in alias for `Where-Object`. Example: `where.exe git*` vs `ls . | where Size -lt 10000` – yzorg Nov 25 '19 at 16:19
-
@ferrell_io So I use the same pattern for `file.exe` vs .NET static class, which you might need in the same script that is detecting encoding. Example: `[File]::SetCreationTime("readme.md", [DateTime]::Now)`. – yzorg Nov 25 '19 at 16:19
you can simply check that by opening your git bash on the file location then running the command file -i file_name
example
user filesData
$ file -i data.csv
data.csv: text/csv; charset=utf-8

- 7,074
- 10
- 69
- 74
Some C code here for reliable ascii, bom's, and utf8 detection: https://unicodebook.readthedocs.io/guess_encoding.html
Only ASCII, UTF-8 and encodings using a BOM (UTF-7 with BOM, UTF-8 with BOM, UTF-16, and UTF-32) have reliable algorithms to get the encoding of a document. For all other encodings, you have to trust heuristics based on statistics.
EDIT:
A powershell version of a C# answer from: Effective way to find any file's Encoding. Only works with signatures (boms).
# get-encoding.ps1
param([Parameter(ValueFromPipeline=$True)] $filename)
begin {
# set .net current directoy
[Environment]::CurrentDirectory = (pwd).path
}
process {
$reader = [System.IO.StreamReader]::new($filename,
[System.Text.Encoding]::default,$true)
$peek = $reader.Peek()
$encoding = $reader.currentencoding
$reader.close()
[pscustomobject]@{Name=split-path $filename -leaf
BodyName=$encoding.BodyName
EncodingName=$encoding.EncodingName}
}
.\get-encoding chinese8.txt
Name BodyName EncodingName
---- -------- ------------
chinese8.txt utf-8 Unicode (UTF-8)
get-childitem -file | .\get-encoding

- 23,033
- 6
- 64
- 66
-
2@jeasoft Thanks. I added in a fix to set the .net current directory. https://stackoverflow.com/questions/11246068/why-dont-net-objects-in-powershell-use-the-current-directory – js2010 Sep 27 '19 at 00:32
Looking for a Node.js/npm solution? Try encoding-checker:
npm install -g encoding-checker
Usage
Usage: encoding-checker [-p pattern] [-i encoding] [-v]
Options:
--help Show help [boolean]
--version Show version number [boolean]
--pattern, -p, -d [default: "*"]
--ignore-encoding, -i [default: ""]
--verbose, -v [default: false]
Examples
Get encoding of all files in current directory:
encoding-checker
Return encoding of all md
files in current directory:
encoding-checker -p "*.md"
Get encoding of all files in current directory and its subfolders (will take quite some time for huge folders; seemingly unresponsive):
encoding-checker -p "**"
For more examples refer to the npm docu or the official repository.

- 1,339
- 1
- 15
- 26
File Encoding Checker is a GUI tool that allows you to validate the text encoding of one or more files. The tool can display the encoding for all selected files, or only the files that do not have the encodings you specify.
File Encoding Checker requires .NET 4 or above to run.

- 3,020
- 1
- 16
- 11
Similar to the solution listed above with Notepad, you can also open the file in Visual Studio, if you're using that. In Visual Studio, you can select "File > Advanced Save Options..."
The "Encoding:" combo box will tell you specifically which encoding is currently being used for the file. It has a lot more text encodings listed in there than Notepad does, so it's useful when dealing with various files from around the world and whatever else.
Just like Notepad, you can also change the encoding from the list of options there, and then saving the file after hitting "OK". You can also select the encoding you want through the "Save with Encoding..." option in the Save As dialog (by clicking the arrow next to the Save button).

- 372
- 6
- 17
-
Nice but when I try to open the file with Visual Studio, it always open the file in the associated text editor (Notepad++ for this kind of file extension). – barbara.post Aug 23 '17 at 12:45
-
@barbara.post that'd be something to do with your Visual Studio settings, I'd think. I've been able to access any plain text files of any type in Visual Studio. You've probably told it to just go to Notepad++ whenever it encounters a file with that extension. That's my thoughts, at least. – JaykeBird Sep 12 '17 at 08:42