Skip to content

Instantly share code, notes, and snippets.

@azihassan
Created September 26, 2014 15:53
Show Gist options
  • Save azihassan/c2fe1aeebb125ffe1cdc to your computer and use it in GitHub Desktop.
Save azihassan/c2fe1aeebb125ffe1cdc to your computer and use it in GitHub Desktop.
Recursively copies the given "file" to all the directories inside the "root" folder. http://www.hackforums.net/showthread.php?tid=4462689&pid=42561339
import std.stdio;
import std.file;
import std.path : buildPath;
import std.exception : enforce;
int main(string[] args)
{
string root;
string file;
if(args.length < 3)
{
writefln("Usage : %s root_dir file", args[0]);
return 0;
}
root = args[1];
file = args[2];
enforce(file.exists, file ~ " does not exist.");
auto entries = dirEntries(root, SpanMode.depth);
while(!entries.empty)
{
try
{
entries.popFront;
if(entries.front.isDir)
copy(file, buildPath(entries.front, file));
}
catch(FileException e)
{
writeln("Failed to copy ", file, " to ", entries.front, " : ", e.msg);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment