RosettaCodeData/Task/Find-common-directory-path/D/find-common-directory-path.d

15 lines
503 B
D
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
import std.stdio, std.string, std.algorithm, std.path, std.array;
2014-01-17 05:32:22 +00:00
string commonDirPath(in string[] paths, in string sep = "/") pure {
2013-04-10 21:29:02 -07:00
if (paths.empty)
return null;
return paths.map!(p => p.split(sep)).reduce!commonPrefix.join(sep);
}
void main() {
2014-01-17 05:32:22 +00:00
immutable paths = ["/home/user1/tmp/coverage/test",
"/home/user1/tmp/covert/operator",
"/home/user1/tmp/coven/members"];
2013-04-10 21:29:02 -07:00
writeln(`The common path is: "`, paths.commonDirPath, '"');
}