0

My goal was to make the "test.txt" file create it with "UTF-8" encoding instead of creating it in "ANSI". I leave attached the whole batch file:

@echo off
cls

break > test.txt

pushd "C:\Users\MARKETING 1\Desktop\SHARED" || exit /B 1
for /D %%D in ("*") do (
    rd /S /Q "%%~D"
)
for %%F in ("*") do (
    if /I not "%%~nxF"=="FILES SAVED HERE WILL BE AUTOMATICALLY DELETED EVERY SATURDAY.txt" del "%%~F"
)
popd

start test.txt

echo %DATE% %TIME% >> test.txt

if %errorlevel% NEQ 1 Echo ERROR DETECTED>>test.txt
if %errorlevel% EQU 1 Echo No error detected>>test.txt

if %errorlevel% NEQ 1 (echo No errors found) ELSE (echo ERROR DETECTED)>>test.txt
if %errorlevel% EQU 1 echo No errors found || echo ERROR DETECTED>>test.txt
 
dir "C:\Users\MARKETING 1\Desktop\SHARED">>test.txt

The file that should have "UTF-8" encoding is the file named "test.txt".

I put a string of the batch file for you to understand better:

break > test.txt
1
  • 1
    Why do you need the start test.txt command?
    – harrymc
    Mar 30, 2023 at 14:31

1 Answer 1

2

How do I create a UTF-8 encoded file from with in batch file?

Add the following line at the start of your batch file:

chcp 65001 > nul

Source: Answer by Martin Prikryl

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .