+ -
当前位置:首页 → 问答吧 → 如何取得 unicode 档案名

如何取得 unicode 档案名

时间:2014-06-19

来源:互联网

手头有档案名称含unicode, e.g. 逆转未来.pdf
求教, 如何取得此名称?

I mean:
在folder见、用 dir, 知道有档案"逆转未来.pdf"
但想用batch取得档案名称, e.g. dir > list.txt
list.txt 中却见 : 逆?未?.pdf

E.g. Try...
1. dir *.pdf
2. dir *.pdf | more
不同, 只有1.是unicode.

作者: 111x111=12321   发布时间: 2014-06-19

没有高手?

作者: 111x111=12321   发布时间: 2014-06-19

before dir > list.txt, type:
chcp 65001

作者: tedbef   发布时间: 2014-06-19

引用:原帖由 tedbef 於 2014-6-16 11:07 AM 发表
before dir > list.txt, type:
chcp 65001
It works, thank you very much.

之前不断试 cmd /u 唔得.

C:\>cmd /?
Starts a new instance of the Windows XP command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
[[/S] [/C | /K] string]

/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be Unicode

作者: 111x111=12321   发布时间: 2014-06-19

cmd /u 得格。出黎个档案系 unicode LE 码。用适当的 txt editor,正确的 code page 咪开到囉。

unicall.bat
cmd /u /c call dirlist.bat
exit

dirlist.bat
dir > filenames.txt
exit

作者: 斋煎   发布时间: 2014-06-19

引用:原帖由 斋煎 於 2014-6-16 05:12 PM 发表
cmd /u 得格。出黎个档案系 unicode LE 码。用适当的 txt editor,正确的 code page 咪开到囉。

unicall.bat
cmd /u /c call dirlist.bat
exit

dirlist.bat
dir > filenames.txt
exit
「用适当的 txt editor,正确的 code page 咪开到囉。」

I tried Notepad.exe & I.E., native windows component, 是适当吧.
后者可选编码, ANYWAY, BOTH FAILED.



E.g. I.E. 编码 unicode
胆馪@S E -N茎胆馪/f E 胆馪@S耧_�: B845-A14B E:\ 茎襒�2014.06.10 12:47 11,762 蓠�*geg.pdf 2 P垪Hh 93,134 MOCQD} 0 P襒� 496,947,200 MOCQD}糇(u

作者: 111x111=12321   发布时间: 2014-06-19

用 ms word 试下吧。

作者: 斋煎   发布时间: 2014-06-19

再唔系将个 txt file 转码做 utf8 又得,其实好多方法。

作者: 斋煎   发布时间: 2014-06-19

引用:原帖由 斋煎 於 2014-6-16 11:33 PM 发表
用 ms word 试下吧。

MS-WORD 卒之得.
太辛苦啦.
入左 WORD 佢知道系乱码, 叫拣, 拣拣拣 unicode 卒之得.
不过唔save 得, 要变做 .DOC, 即系 for your eyes only.

我想拿来用.
E.g. my.bat
copy 逆转未来.pdf D:

作者: 111x111=12321   发布时间: 2014-06-19

将个 doc 用 acrobat 开然后 save as pdf 咪掂囉。

其实有很多方法。不同需要用不同的途径。如果一次性的,最简单是用 explorer,cntl A,shift right click,copy as path,入 acrobat,paste,save,就系咁简单。

用 script 做其实仲可以 pipe to clip.exe,然后在 pdf editor paste 返 clipboard。

各种方法各有各好。

作者: 斋煎   发布时间: 2014-06-19

引用:原帖由 斋煎 於 2014-6-17 07:27 AM 发表
将个 doc 用 acrobat 开然后 save as pdf 咪掂囉。

其实有很多方法。不同需要用不同的途径。如果一次性的,最简单是用 explorer,cntl A,shift right click,copy as path,入 acrobat,paste,save,就系咁简单。 ...
唔系o番, 你改晒我既要求,
你误会左.
我唔系依家有个file要搞, 如果系, 我用gui, mouse drag啦.
我想知道依次序系concept(明明地就够), 重要系automate (*.bat, script, any language (treat as data no presentation, so codepage is not a problem)), 最后先系"呢个file去D:" ("将个 doc 用 acrobat 开然后 save as pdf 咪掂囉"@@)



copy 逆转未来.pdf D: 只是劳作习作, see the word "e.g."?

作者: 111x111=12321   发布时间: 2014-06-19

其实 op 解决了问题未?logic 很简单的。

chcp 的方法是先更改 console codepage to xxxxx (default 是 950 中文繁体),然后 dir/tree pipe to 一个 txt file。
cmd /u 的方法是另开一个 unicode LE console,在这 console 里完成工作,然后跳回原来的 console。

output 既 txt file 的 codepage,第一个方法黎讲便是你指定的 xxxxx,第二个方法是固定了为 unicode LE。

之后将这个 txt file 点搅是后面的事。
要转 codepage 的话可用第三方软件,例如 iconv,windows 没有原生指令做这。
转 format 成 pdf 也是用第三方软件。

作者: 斋煎   发布时间: 2014-06-19

似乎两个方法指去不同 codepage, 后者(unicode LE)比较占位, 连非中文都用上 unicode编码, 所以"复杂" (要经WORD, Notepad,IE都唔认).

Ok, e.g. 我想完成呢个习作....
用方法一, 经notepad整理, 可得 1.bat, 内容为
dir 逆转未来.pdf
Run 个 1.bat 会 fail. 原因我知唔使讨论, 但点解决?

FYI:
其实1.bat 经另一种方法fail (原本都会fail, 因为个 1.bat text file有unicode prefix),
当 chcp 65001, 所以 .bat都唔行.
E.g. 2.bat 只得一句, echo Hello (OR pause, WHATEVER), 即return冇output

作者: 111x111=12321   发布时间: 2014-06-19

Similarly, 我拿住一个string "逆转未来.pdf",
用 windows api FindFirstFile, 点先work?
个string系咩编码?

作者: 111x111=12321   发布时间: 2014-06-19