Last active
February 16, 2016 05:24
-
-
Save thosakwe/5775e540d98ddbc73178 to your computer and use it in GitHub Desktop.
Recursively copy a directory in Dart by running CMD/Bash commands. Uses robocopy on Windows and cp on Mac/*NIX.
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
Future<bool> copy(Directory source, Directory destination) async { | |
String processName = Platform.isWindows ? "robocopy" : "cp"; | |
List <String> args; | |
if (Platform.isWindows) | |
args = [source.absolute.path, destination.absolute.path, '/E', '/B']; | |
else | |
args = ['-r', source.absolute.path, destination.absolute.path]; | |
Process cp = await Process.start(processName, args); | |
cp.stdout.listen(null); // For some reason, robocopy won't copy directories unless you listen to stdout | |
stderr.addStream(cp.stderr); | |
int code = await cp.exitCode; | |
return (Platform.isWindows && code <= 1) || | |
(!Platform.isWindows && code == 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment