Use coding system coding for encoding and decoding file
The command C-x RET F (
specifies a coding system to use for encoding file names. It
has no effect on reading and writing the contents of files.
In fact, all this command does is set the value of the variable
file-name-coding-system. If you set the variable to a coding
system name (as a Lisp symbol or a string), Emacs encodes file names
using that coding system for all file operations. This makes it
possible to use non-ASCII characters in file names—or, at
least, those non-ASCII characters that the specified coding
system can encode.
nil, Emacs uses a
default coding system determined by the selected language environment,
and stored in the
In the default language environment, non-ASCII characters in
file names are not encoded specially; they appear in the file system
using the internal Emacs representation.
When Emacs runs on MS-Windows versions that are descendants of the
NT family (Windows 2000, XP, Vista, Windows 7, and Windows 8), the
file-name-coding-system is largely ignored, as Emacs
by default uses APIs that allow to pass Unicode file names directly.
By contrast, on Windows 9X, file names are encoded using
file-name-coding-system, which should be set to the codepage
(see codepage) pertinent for the current system
locale. The value of the variable
controls whether Emacs uses the Unicode APIs when it calls OS
functions that accept file names. This variable is set by the startup
nil on Windows 9X, and to
t on newer versions of
Warning: if you change
file-name-coding-system (or the
language environment) in the middle of an Emacs session, problems can
result if you have already visited files whose names were encoded using
the earlier coding system and cannot be encoded (or are encoded
differently) under the new coding system. If you try to save one of
these buffers under the visited file name, saving may use the wrong file
name, or it may encounter an error. If such a problem happens, use C-x
C-w to specify a new file name for that buffer.
If a mistake occurs when encoding a file name, use the command M-x recode-file-name to change the file name’s coding system. This prompts for an existing file name, its old coding system, and the coding system to which you wish to convert.