使用NewLISP查找中文文件名的属性?
下面的NewLISP代码显示了Win32下文件的文件属性。但是,检索到的某些文件名中包含中文字符。当 GetFileAttributesA 函数遇到它们时,它会给我该属性 -1。我查看了 GetFileAttributesW 但不知道如何使 fname 的内容以其识别的形式可供函数使用。
如何处理这种情况? (我愿意考虑尝试另一种语言)
(define (get-archive-flag file-name)
(if (not GetFileAttributesA)
(begin
(import "kernel32.DLL" "GetFileAttributesA")
)
)
(setq fname file-name file-attrib (GetFileAttributesA (address fname)))
(append fname " " ( string file-attrib))
)
; walks a disk directory and prints all path-file names
;
(define (show-tree dir)
(if (directory dir)
(dolist (nde (directory dir))
(if (and (directory? (append dir "/" nde))
(!= nde ".") (!= nde ".."))
(show-tree (append dir "/" nde))
(println (get-archive-flag (append dir "/" nde)))
)
)
)
)
(show-tree "z:\\working files\\Cathy")
The following NewLISP code shows me the file attributes of files under Win32. However, some of the filenames retrieved have Chinese characters in the name. When the GetFileAttributesA function encounters them, it gives me a -1 for the attribute. I looked at GetFileAttributesW but don't know how to make the contents of the fname available to the function in a form it recognises.
How does one handle this situation? (I am willing to consider trying another language)
(define (get-archive-flag file-name)
(if (not GetFileAttributesA)
(begin
(import "kernel32.DLL" "GetFileAttributesA")
)
)
(setq fname file-name file-attrib (GetFileAttributesA (address fname)))
(append fname " " ( string file-attrib))
)
; walks a disk directory and prints all path-file names
;
(define (show-tree dir)
(if (directory dir)
(dolist (nde (directory dir))
(if (and (directory? (append dir "/" nde))
(!= nde ".") (!= nde ".."))
(show-tree (append dir "/" nde))
(println (get-archive-flag (append dir "/" nde)))
)
)
)
)
(show-tree "z:\\working files\\Cathy")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
自 10.3.2 版本(2011 年 7 月 20 日发布) 10.3.2 起,在读取路径/文件名时,MultiByteToWideChar 由 newLISP 在内部处理。
Since version 10.3.2, relased July 20th 2011, 10.3.2 , MultiByteToWideChar is handled internally by newLISP when reading path/file names.
也许您不使用 Newlisp 的 Unicode 版本。无论如何,这里的 Newlispers 很少。请尝试 Newlisp 论坛。
Maybe you do not use Unicode version of Newlisp. Anycase, there are very few Newlispers here. Try Newlisp forum instead.
为了完整起见,这是与 NewLISP 论坛。
我还没有用更合适的
&
运算符替换属性位上的位切片反转
技术。这就留给读者了。For the sake of completeness, here's the solution, found in consultation with the folk on the NewLISP forum.
I haven't replaced the
bits slice reverse
technique on the attribute bit with the more appropriate&
operator. That's left for the reader.