关于dlang语言的file模块以下内容请用好看的markdown翻译成中文内容如下:SysTime timeLastModifiedRR name SysTime returnIfMissingif isSomeFiniteCharInputRange!R;Returns the time that the given file was last modified If the file doe
file模块
timeLastModified
SysTime timeLastModified(R)(R name, SysTime returnIfMissing)
if (isSomeFiniteCharInputRange!R);
返回给定文件最后修改的时间。如果文件不存在,则返回 returnIfMissing。
在构建自动化工具(如make或ant)中经常使用此函数的模式,用于检查是否必须从文件源中重建文件目标(即,目标早于源或不存在)。下面的代码在源文件不存在时会抛出FileException异常(应该是这样)。然而,SysTime.min的默认值使不存在的目标看似无限旧,因此测试正确地提示要构建它。
参数:
R name:要获取修改时间的文件名。SysTime returnIfMissing:如果给定的文件不存在,则返回的时间。
返回:
一个 std.datetime.systime.SysTime。
示例:
if (source.timeLastModified >= target.timeLastModified(SysTime.min))
{
// must (re)build
}
else
{
// target is up-to-date
}
timeLastModified (POSIX-Only)
pure nothrow SysTime timeLastModified()(auto ref stat_t statbuf);
返回给定文件最后修改的时间。
参数:
stat_t statbuf:从文件中检索的stat_t。
timeLastAccessed (POSIX-Only)
pure nothrow SysTime timeLastAccessed()(auto ref stat_t statbuf);
返回给定文件最后访问的时间。
参数:
stat_t statbuf:从文件中检索的stat_t。
timeStatusChanged (POSIX-Only)
pure nothrow SysTime timeStatusChanged()(auto ref stat_t statbuf);
返回给定文件状态最后更改的时间。
参数:
stat_t statbuf:从文件中检索的stat_t。
exists
bool exists(R)(R name)
if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R);
或
bool exists(R)(auto ref R name)
if (isConvertibleToString!R);
确定给定的文件(或目录)是否存在。
参数:
R name:表示文件名的字符串或字符范围。
返回:
如果作为输入指定的文件名存在,则为 true。
示例:
auto f = deleteme ~ "does.not.exist";
assert(!f.exists);
f.write("hello");
assert(f.exists);
f.remove;
assert(!f.exists);
``
原文地址: http://www.cveoy.top/t/topic/gSs2 著作权归作者所有。请勿转载和采集!