View source code Display the source code in std/file.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.file.time_last_modified - multiple declarations

Function timeLastModified

Returns the time that the given file was last modified. If the file does not exist, returns returnIfMissing.

A frequent usage pattern occurs in build automation tools such as make or ant. To check whether file target must be rebuilt from file source (i.e., target is older than source or does not exist), use the comparison below. The code throws a FileException if source does not exist (as it should). On the other hand, the SysTime.min default makes a non-existing target seem infinitely old so the test correctly prompts building it.

Prototype

SysTime timeLastModified(R)(
  R name,
  SysTime returnIfMissing
)
if (isInputRange!R && isSomeChar!(ElementEncodingType!R));

Parameters

NameDescription
name The name of the file to get the modification time for.
returnIfMissing The time to return if the given file does not exist.

Examples

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

Function timeLastModified

Returns the time that the given file was last modified.

Prototype

SysTime timeLastModified(R)(
  R name
)
if (isInputRange!R && isSomeChar!(ElementEncodingType!R));

Throws

FileException if the given file does not exist.

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis

License

Boost License 1.0.

Comments