Writing file with the encode command
You can use the Action Script command action uses file encoding
to
specify the encoding in which to write files when using the appendfile and createfile until commands.
The encoding is effective until another encoding is specified. If you do not use the
action uses file encoding
command, the appendfile
and
createfile
commands create files in the local encoding.
The command syntax is:
action uses file encoding encoding [ NoBOM ]
The encoding might be any name which ICU can recognize, such as
ISO-8859-1
, Shift_JIS
, and UTF-8
. After created,
the file
objects can be used as regular file
objects and you can
apply any operations applicable to text files.
To turn off the encoding change and reuse the local encoding, you can set the encoding keyword to
local
.
If any of the UTF encodings (UTF-8, UTF-16, or UTF-32) is specified as the value of encoding, the file to be created will have a BOM (Byte Order Mark) at the head of it. If the client local encoding is UTF-8 and no encoding is specified in an action, files to be created with the action will be written in UTF-8 without BOM.
To suppress adding any BOM, you can use the option NoBOM
(case-insensitive)
following the value of encoding. The NoBOM
option is effective only with any
UTF encodings (UTF-8, UTF-16, and UTF-32), and it is ignored if it is used with any other encoding
name.
delete "{(client folder of current site as string) & "/__appendfile"}"
action uses file encoding Windows-1253
appendfile Κόκκινο ου?ανό τη ν?χτα
delete C:\encode_test.txt
move __appendfile C:\encode_test.txt
delete "{(client folder of current site as string) & "/__appendfile"}"
appendfile Following lines contains Greek language strings
action uses file encoding Windows-1253
appendfile Κόκκινο ου?ανό τη ν?χτα
move __appendfile C:\Greek_test.txt
// switch to local encode
delete "{(client folder of current site as string) & "/__appendfile"}"
appendfile Following lines contains English strings
action uses file encoding local
appendfile Am I writing a local US strings now !
delete C:\tmp\local_test.txt
move __appendfile C:\tmp\local_test.txt
delete "{(client folder of current site as string) & "/__appendfile"}"
action uses file encoding UTF-8 noBOM
appendfile Hello world !!
delete /tmp/encode_test.txt
move __appendfile /tmp/encode_test.txt