How Can I Rar a File with a Unicode Name in Batch

I wrote a small batch file to rar all contents in all subfolders within a folder. It works fine except for that the file names should be in ASCII. Below is the working small code:

@REM ------- BEGIN rarthem.bat ----------------
@echo off
echo --------------------------------------------------
echo Starting to rar files
echo --------------------------------------------------
set path="C:\Program Files\WinRAR\";%path%
for /D /r %%G in ("*") do (
    echo Storing files in %%G
    echo --------------------------------------------------

    cd %%G

    for %%I in (*.*) do (
        rar a -x*.rar -x*.zip -m0 -id[c] "%%~nI.rar" "%%I"
        echo Done archiving %%~nI%%~xI

    echo --------------------------------------------------
    echo Done archiving %%~nG
    echo --------------------------------------------------
    cd ..

echo Finished!
REM ------- END rarthem.bat ------------------

I think the problem happens when the file name is parsed to WinRAR as WinRAR has no problem archiving files with Unicode names.

Edit: When parsing the file name to WinRAR, the file name gets modified so when WinRAR tries to look for the file under that name, it can't find it. For example a file: téxt.pdf will become text.pdf when parsed.

A small side question: I've not tried using 7zip, would it be easier to achieve the same thing with 7zip?

Many thanks for help.


RAR.exe processes its command-line in the OEM character set (i.e. not unicode). The only way I know of to pass a unicode name to it is via a list file, when also using the argument to specify that the list file is unicode. However, that only works for files inside the archive (EDIT: or files you want to add to the archive). For the archive name itself I don't know of a solution except...

If you use WinRAR.exe instead of RAR.exe then you can pass unicode filenames on the command-line and they work fine. You will see a GUI progress window but other than that (which may or may not matter to you) WinRAR.exe is suitable for running from batch scripts.

Whether a batch script itself can cope with unicode I do not know, but if that is the only problem remaining I would switch to using VBScript or JScript instead of a batch file. (Which is worth doing anyway, IMO. I'm not a big fan of VBScript and JScript but at least they don't have completely insane, arcane semantics and limitations like batch does. :))

By the way, if you do use WinRAR.exe you might want to get the recent WinRAR 4 (beta 2 currently) as it includes the ability to specify the working directory, previously only possible with rar.exe. That can be essential if you need to add files from read-only directories.

If you want to learn about the list files I mentioned, check the RAR.exe text-file document or the WinRAR.exe built-in online help for all the details.

Hope that helps!

Need Your Help

CDI deployment failure:WELD-001414 Bean name is ambiguous

java maven cdi glassfish-4 weld

I have an application, which have multiple modules and various dependencies. When I deploy the application on Glassfish 4, I am getting error:

How to delete file/folder in a blocking way?

c++ file-io blocking boost-filesystem

What I'm looking for is a way to block the thread until it succeeds to delete a folder using boost-filesystem.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.