Created
September 26, 2014 15:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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