我有一堆用日语命名的XML文件。我使用Lua读取它们并将必要的信息放入表中。我可以打开仅像名字.xml一样在单个汉字中命名的文件,但对于像名前.xml这样的多个汉字,它是逆向的。在运行Lua文件之前,我将命令行的代码页设置为65001(以UTF-8为单位)。并且要使用从ACP(ASCII代码页?)到UTF-8的WinAPI库来读取我需要编码文件名的文件,但是这种编码仅适用于单个kanjis。我已经在互联网上尝试了几个建议,使用文件的短路径等,但没有一个有效。我尝试通过以管理员身份运行Lua来使用短路径 - 正如其他类似问题中所述,您需要管理员优先使用短路径 - 但没有运气。
...
for fn in io.popen("DIR xml /B /AA"):lines() do
...
local f = assert(io.open("xml\\" .. winapi.encode(winapi.CP_UTF8, winapi.CP_ACP, fn), "rb"))
...
end
...
但是我的代码产生了#34;无效的参数"错误。我搜索了这个错误,但没有一个是Lua相关的,所以我打开了与C / C ++相关的错误,但我得到的只是'使用_wfopen
'或类似的东西。它没有在Lua中实现,我也不想自己实现它。所以任何人都知道如何解决这个问题?有关更多信息,请务必告诉我。谢谢!
答案 0 :(得分:2)
我不知道为什么你的程序不起作用,但试试这个解决方法:
local pipe = io.popen([[for %G in (xml\*) do @(type "%G" & echo @FILENAMEMARKER#%G)]], "rb")
local all_files = pipe:read"*a"
pipe:close()
for filecontent, filename in all_files:gmatch"(.-)@FILENAMEMARKER#(.-)\r?\n" do
-- process your file here
print('===== This is your file name:')
print(filename)
print('== This is your file content:')
print(filecontent)
print('== End of file')
end
答案 1 :(得分:0)
我认为您可以在
这样的表格中使用日语字母local jaAlphbet={"一","|","丶","ノ","乙","亅","<","二","亠","人","⺅","","儿","入","ハ","丷","冂","冖","冫","几","凵","刀","⺉","力","勹","匕","匚","十","卜","卩","厂","厶","又","マ","九","ユ","乃","","⻌","口","囗","土","士","夂","夕","大","女","子","宀","寸","小","⺌","尢","尸","屮","山","川","巛","工","已","巾","干","幺","广","廴,"廾","弋","弓","ヨ","彑","彡","彳","⺖","⺘","⺡","⺨","⺾","⻏","⻖","也","亡","及","久","⺹","心","戈","戸","手","支","攵","文","斗","斤","方","无","日","曰","月","木","欠","止","歹","殳","比","毛","氏","气","水","火","⺣","爪","父","爻","爿","片","牛","犬","⺭","王","元","井","勿","尤","五","屯","巴","毋","玄","瓦","甘","生","用","田","疋","疒","癶","白","皮","皿","目","矛","矢","石","示","禸","禾","穴","立","⻂","世","巨","冊","母","⺲","牙","瓜","竹","米","糸","缶","羊","羽","而","耒","耳","聿","肉","自","至","臼","舌","舟","艮","色","虍","虫","血","行","衣","西","臣","見","角","言","谷","豆","豕","豸","貝","赤","走","足","身","車","辛","辰","酉","釆","里","舛","麦","金","長","門","隶","隹","雨","青","非","奄","岡","免","斉","面","革","韭","音","頁","風","飛","食","首","香","品","馬","骨","高","髟","鬥","鬯","鬲","鬼","竜","韋","魚","鳥","鹵","鹿","麻","亀","啇","黄","黒","黍","黹","無","歯","黽","鼎","鼓","鼠","鼻","齊","龠"}
print(jaAlphbet[1])--and you can call the letters, letter by letter
抱歉,但这就是我所知道的你所谈论的主题,但我希望这有帮助