如何批量rar带有Unicode名称的文件

发布于 2024-10-05 20:18:25 字数 1117 浏览 0 评论 0原文

我编写了一个小批处理文件来 rar 文件夹内所有子文件夹中的所有内容。除了文件名应该是 ASCII 之外,它工作正常。下面是工作的小代码:

@REM ------- BEGIN rarthem.bat ----------------
@setlocal
@echo off
echo --------------------------------------------------
echo Starting to rar files
echo --------------------------------------------------
echo.
echo.
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 --------------------------------------------------
    echo.
    echo.
    cd ..
)

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

我认为当文件名解析为 WinRAR 时会出现问题,因为 WinRAR 归档具有 Unicode 名称的文件没有问题。

编辑:将文件名解析为 WinRAR 时,文件名会被修改,因此当 WinRAR 尝试查找该名称下的文件时,它找不到它。例如,文件:text.pdf 在解析时将变为 text.pdf。

一个小问题:我没有尝试过使用 7zip,使用 7zip 实现同样的事情会更容易吗?

非常感谢您的帮助。

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 ----------------
@setlocal
@echo off
echo --------------------------------------------------
echo Starting to rar files
echo --------------------------------------------------
echo.
echo.
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 --------------------------------------------------
    echo.
    echo.
    cd ..
)

echo Finished!
pause
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林很绿却致人迷途 2024-10-12 20:18:25

RAR.exe 以 OEM 字符集(即不是 unicode)处理其命令行。我知道向其传递 unicode 名称的唯一方法是通过列表文件,同时还使用参数指定列表文件是 unicode。但是,这只适用于存档内的文件(编辑:或要添加到存档中的文件)。对于存档名称本身,我不知道解决方案,除非...

如果您使用 WinRAR.exe 而不是 RAR.exe,那么您可以在命令行上传递 unicode 文件名,并且它们可以正常工作。您将看到一个 GUI 进度窗口,但除此之外(这对您可能重要也可能不重要)WinRAR.exe 适合从批处理脚本运行。

我不知道批处理脚本本身是否可以处理 unicode,但如果这是唯一剩下的问题,我会改用 VBScript 或 JScript 而不是批处理文件。 (无论如何,这都是值得做的,IMO。我不是 VBScript 和 JScript 的忠实粉丝,但至少它们没有像批处理那样完全疯狂、神秘的语义和限制。:))

顺便说一句,如果你确实使用WinRAR.exe 您可能想要获取最新的 WinRAR 4(当前为 beta 2),因为它包含指定工作目录的功能,而以前只能通过 rar.exe 实现。如果您需要从只读目录添加文件,这可能是必不可少的。

如果您想了解我提到的列表文件,请检查 RAR.exe 文本文件文档或 WinRAR.exe 内置在线帮助以获取所有详细信息。

希望有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文