Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a built-in function to copy a directory in Dart?

Is there a built-in function to copy a directory and recursively copy all the files (and other directories) in Dart?

like image 302
Will Squire Avatar asked Nov 29 '14 17:11

Will Squire


People also ask

How do I copy files in darts?

copy methodCopy this file. Returns a Future<File> that completes with a File instance for the copied file. If newPath identifies an existing file, that file is replaced. If newPath identifies an existing directory, the operation fails and the future completes with an exception.

Can you copy a directory?

Alternatively, right-click the folder, select Show more options and then Copy. In Windows 10 and earlier versions, right-click the folder and select Copy, or click Edit and then Copy. Navigate to the location where you want to place the folder and all its contents.

Which method is used to copy a directory to another location ()?

copy() method in Python is used to copy the content of source file to destination file or directory.

What command is used to copy files in a directory?

The cp Command cp stands for copy. This command is used to copy files or group of files or directories. It creates an exact copy of a file on a disk with different file name. cp command requires at least two filenames in its arguments.


1 Answers

No, not to my knowledge there isn't. But Dart supports basic reading and writing of files from directories, so it stands to reason that this could be solved programmatically.

Check out this gist I found of a tool that would accomplish this process.

Basically, you would search the directory for files you wanted to copy and perform the copy operation:

newFile.writeAsBytesSync(element.readAsBytesSync());

to all file paths, new Path(element.path);, in the new Directory(newLocation);.

Edit:

But this is super inefficient, because the whole files has to be read in by the system and wrote back out to a file. You could just use a shell process spawned by Dart to take care of the process for you:

Process.run("cmd", ["/c", "copy", ...])
like image 191
James Taylor Avatar answered Sep 28 '22 04:09

James Taylor