当文件名可能包含 UTF8 字符时,如何以整数形式获取 DateLastModified?
我正在Windows环境中编写Lua(5.3);结果将在许多国家/地区使用,因此文件处理必须满足多个区域设置(排除 lfs 和 Penlight 库)以及许多日期格式(由用户选择)。
我使用 luacom 和 Microsoft FileObject 访问文件,这消除了文件名问题,但我在使用以文本形式返回的 DateLastModified 属性时遇到了困难。
我需要比较数百个文件的 DateLastModified 以确定哪个是最新的。
我考虑过的一种技术涉及暂时将 PC 的短日期格式设置为可预测的、可以简单解析的格式,例如“yyyy-MM-dd”(然后重新设置),但我本能地反对弄乱用户的注册表设置,尤其是那些在我的程序之外产生影响的设置。
我可以将每个文件复制到一个临时文件,其名称允许 lfs 获取整数秒的修改数据,但这会严重影响应该是相当基本的实用程序的运行时间。
是否有我忽略的解决方案,或者我是否必须选择最不坏的选项?注意:我对目标环境中可用的库非常有限。
I'm writing Lua (5.3) in a Windows environment; the result will be used in many countries so file handling has to cater for multiple locales (which rules out the lfs and Penlight libraries) and also many date formats (as selected by the user).
I'm accessing files using luacom and Microsoft FileObject, which eliminates problems with file names, but I'm having difficulty with the DateLastModified property, which is returned in text.
I need to compare the DateLastModified for many hundreds of files to determine which is the latest.
One technique I've considered would involve temporarily setting (via the registry) the PC's Short Date format to something predictable that can be simply parsed such as "yyyy-MM-dd" (and resetting it afterwards) but I'm instinctively averse to messing with the user's registry settings, especially those that have ramifications outside my program.
I could copy each file to a temporary file with a name that allows lfs to get the modification data as an integer number of seconds, but that would seriously impact the run-time of what's supposed to be a fairly basic utility.
Is there a solution I've overlooked, or am I going to have to choose the least worst option? Note: I'm quite restricted in the libraries available in the target environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管 Luacom 的默认行为是将日期作为文本字符串返回(基于当前语言环境),但可以修改此行为:
来自 Luacom 文档
Although the default behaviour of Luacom is to return a Date as a text string (based on the current locale), it is possible to modify this behaviour:
From Luacom documentation