当文件名可能包含 UTF8 字符时,如何将 DateLastModified 获取为整数?

How can I get the DateLastModified as an integer when filenames may contain UTF8 characters?

我正在 Windows 环境中编写 Lua (5.3);结果将在许多国家/地区使用,因此文件处理必须满足多个区域设置(排除 lfs 和 Penlight 库)以及许多日期格式(由用户选择)。

我正在使用 luacom 和 Microsoft FileObject 访问文件,这消除了文件名问题,但我在使用以文本形式返回的 DateLastModified 属性 时遇到困难。

我需要比较数百个文件的 DateLastModified 以确定哪个是最新的。

我考虑过的一种技术涉及将 PC 的短日期格式临时设置(通过注册表)为可预测的可以简单解析的格式,例如“yyyy-MM-dd”(并在之后重置)但我我本能地反对弄乱用户的注册表设置,尤其是那些在我的程序之外产生影响的设置。

我可以将每个文件复制到一个临时文件,该文件的名称允许 lfs 以整数秒的形式获取修改数据,但这会严重影响本应达到的 运行 时间一个相当基本的实用程序。

是否有我忽略的解决方案,或者我是否必须选择最差的选项?注意:我在目标环境中可用的库非常有限。

虽然 Luacom 的默认行为是 return 将日期作为文本字符串(基于当前语言环境),但可以修改此行为:

3.4.6 DATE type When converting from COM to Lua, the default behavior is to transform DATE values to strings formatted according to the current locale. The converse is true: LuaCOM converts strings formatted according to the current locale to DATE values. The script can change the conversion from strings to tables by setting the DateFormat field of the luacom table (the LuaCOM namespace) to the string "table". The table will have Day, DayOfWeek, Month, Year, Hour, Minute, Second, and Milliseconds fields. To return the conversion to strings, set the DateFormat field to "string". Be careful with this feature, as it may break compatibility with other scripts.

来自Luacom documentation