Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create files/folders with diacritics using a bat script

I have a bat file that reads the lines a file, and then tries to create files or folders, depending on the given argument.

The problem is that when it gets to chars as ăâțîș, it does not work.

This is my code:

IF "%1"=="" GOTO Final
IF "%1"=="file" GOTO File
IF "%1"=="folder" GOTO Folder

:File
    for /f %%i in (files.txt) do echo. > %%i.rtf
GOTO Final

:Folder
    for /f "tokens=*" %%a in (folders.txt) do (
    mkdir "%%a"
    )
GOTO Final

:Final

What I've tried so far using this link: Manage paths with accented characters

  1. The bat script is ANSI
  2. CHCP 1250 > NUL

How can i solve this?

like image 476
Gerald Hughes Avatar asked Jun 07 '26 16:06

Gerald Hughes


1 Answers

Put CHCP XXX into the batch where XXX is a codepage that matches encoding of your text files (files.txt and folders.txt). Note that you can use CHCP 65001 which is equivalent of UTF-8 and should handle most of diactrics without problems.

like image 73
rostok Avatar answered Jun 10 '26 10:06

rostok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!