Skip to content

Instantly share code, notes, and snippets.

@thosakwe
Last active February 16, 2016 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thosakwe/5775e540d98ddbc73178 to your computer and use it in GitHub Desktop.
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.
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