File Module in Dlang

timeLastModified

SysTime timeLastModified(R)(R name, SysTime returnIfMissing)
if (isSomeFiniteCharInputRange!R);

Returns the time that the given file was last modified. If the file does not exist, returns returnIfMissing. This function is frequently used in build automation tools like make or ant to check if a target file needs to be rebuilt from a source file.

Parameters

  • R name: The name of the file to get the modification time for.
  • SysTime returnIfMissing: The time to return if the given file does not exist.

Returns

A std.datetime.systime.SysTime.

Example

if (source.timeLastModified >= target.timeLastModified(SysTime.min))
{
    // must (re)build
}
else
{
    // target is up-to-date
}

exists

bool exists(R)(R name)
if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R);

bool exists(R)(auto ref R name)
if (isConvertibleToString!R);

Determine whether the given file (or directory) exists.

Parameters

  • R name: A string or range of characters representing the file name.

Returns

true if the file name specified as input exists.

Examples

auto f = deleteme ~ "does.not.exist";
assert(!f.exists);

f.write("hello");
assert(f.exists);

f.remove;
assert(!f.exists);

timeLastAccessed

pure nothrow SysTime timeLastAccessed()(auto ref stat_t statbuf);

This function is POSIX-only. Returns the time that the given file was last accessed.

Parameters

  • stat_t statbuf: stat_t retrieved from file.

timeStatusChanged

pure nothrow SysTime timeStatusChanged()(auto ref stat_t statbuf);

This function is POSIX-only. Returns the time that the given file was last changed.

Parameters

  • stat_t statbuf: stat_t retrieved from file
关于dlang语言的file模块以下内容请用好看的markdown翻译内容如下:SysTime timeLastModifiedRR name SysTime returnIfMissingif isSomeFiniteCharInputRange!R;Returns the time that the given file was last modified If the file does n

原文地址: http://www.cveoy.top/t/topic/gSsR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录