关于dlang语言的file模块以下内容请用好看的markdown格式翻译成中文内容如下:const property safe SysTime timeCreated;This function is Windows-OnlyReturns the creation time of the file represented by this DirEntryproperty safe SysTim
const @property @safe SysTime timeCreated(); 此函数仅适用于Windows。返回由DirEntry表示的文件的创建时间。 @property @safe SysTime timeLastAccessed(); 返回DirEntry表示的文件的上一次访问时间。请注意,许多文件系统不会更新文件的访问时间(通常是为了提高性能),因此timeLastAccessed将返回与timeLastModified相同的值的可能性很大。 @property @safe SysTime timeLastModified(); 返回由DirEntry表示的文件的上一次修改时间。 const @property @safe SysTime timeStatusChanged(); 此函数仅适用于POSIX。返回由DirEntry表示的文件的上一次更改时间(不仅限于内容,还包括权限或所有权)。 @property @safe uint attributes(); 返回由DirEntry表示的文件的属性。请注意,Windows和POSIX系统上的文件属性完全不同。在Windows上,它们是由GetFileAttributes GetFileAttributes返回的内容。而在POSIX系统上,它们是st_mode值的一部分,该值是通过调用stat获得的stat结构的一部分。在POSIX系统上,如果由DirEntry表示的文件是符号链接,则属性是指向符号链接的文件的属性。 @property @safe uint linkAttributes(); 在POSIX系统上,如果由DirEntry表示的文件是符号链接,则linkAttributes是符号链接本身的属性。否则,linkAttributes与属性相同。在Windows上,linkAttributes与属性相同。它存在于Windows上,因此在处理符号链接时不必为Windows特别设置代码。 @property @safe stat_t statBuf(); 此函数仅适用于POSIX。通过调用stat获取的stat结构。 preserveAttributesDefault保留属性默认值为是(Yes.preserveAttributes)(仅适用于Windows),在所有其他平台上则相反。 void copy(RF,RT)(RF from,RT to,PreserveAttributes preserve = preserveAttributesDefault) if(isSomeFiniteCharInputRange!RF &&!isConvertibleToString!RF && isSomeFiniteCharInputRange!RT &&!isConvertibleToString!RT);
void copy(RF,RT)(auto ref RF from,auto ref RT to,PreserveAttributes preserve = preserveAttributesDefault) if(isConvertibleToString!RF || isConvertibleToString!RT); 从一个文件复制到另一个文件。文件时间戳被保留。如果preserve等于Yes.preserveAttributes,则保留文件属性。仅在Windows上支持Yes.preserveAttributes(Windows上的默认设置)。如果目标文件存在,则覆盖它。 参数: RF from 表示现有文件名的字符串或字符范围 RT to 表示目标文件名的字符串或字符范围 PreserveAttributes preserve 是否保留文件属性 抛出: 在出现错误时引发FileException。 示例: auto source = deleteme ~ "source"; auto target = deleteme ~ "target"; auto targetNonExistent = deleteme ~ "target2";
scope(exit) source.remove, target.remove, targetNonExistent.remove;
source.write("source"); target.write("target");
writeln(target.readText); // "target"
source.copy(target); writeln(target.readText); // "source"
source.copy(targetNonExistent); writeln(targetNonExistent.readText); // "source" Edit RunOpen in IDE @safe void rmdirRecurse(scope const(char)[] pathname);
@safe void rmdirRecurse(ref scope DirEntry de);
@safe void rmdirRecurse(scope DirEntry de); 递归删除目录及其所有内容和子目录。 参数: const(char)[] pathname 要完全删除的目录的路径 DirEntry de 要删除的DirEntry 抛出: 如果出现错误(包括给定文件不是目录),则引发FileException。 示例: import std.path : buildPath;
auto dir = deleteme.buildPath("a", "b", "c");
dir.mkdirRecurse; assert(dir.exists);
deleteme.rmdirRecurse; assert(!dir.exists); assert(!deleteme.exists); Edit RunOpen in IDE 跳转到:广度 · 深度 · 浅层
enum SpanMode: int; 指定dirEntries的目录跨度策略(见下文)。 示例: import std.algorithm.comparison : equal; import std.algorithm.iteration : map; import std.algorithm.sorting : sort; import std.array : array; import std.path : buildPath, relativePath;
auto root = deleteme ~ "root"; scope(exit) root.rmdirRecurse; root.mkdir;
root.buildPath("animals").mkdir; root.buildPath("animals", "cat").mkdir;
alias removeRoot = (return scope e) => e.relativePath(root);
assert(root.dirEntries(SpanMode.depth).map!removeRoot.equal( [buildPath("animals", "cat"), "animals"]));
assert(root.dirEntries(SpanMode.breadth).map!removeRoot.equal( ["animals", buildPath("animals", "cat")]));
root.buildPath("plants").mkdir;
assert(root.dirEntries(SpanMode.shallow).array.sort.map!removeRoot.equal( ["animals", "plants"])); Edit RunOpen in IDE 浅层 仅跨越一个目录。 深度 以深度优先后序方式跨越目录,即任何子目录的内容在子目录本身之前跨越。在递归删除文件时很有用。 广度 以深度优先先序方式跨越目录,即任何子目录的内容紧随其自身之后跨越。请注意,SpanMode.breadth不会导致所有目录成员在任何子目录成员之前出现,即它不是真正的广度优先遍历
原文地址: http://www.cveoy.top/t/topic/gSBP 著作权归作者所有。请勿转载和采集!