是否有一个内置函数来复制Dart中的目录? [英] Is there a built-in function to copy a directory in Dart?

查看:519
本文介绍了是否有一个内置函数来复制Dart中的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个内置函数来复制目录并递归复制Dart中的所有文件(和其他目录)?

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

推荐答案

不,不是我的知识没有。但是Dart支持从目录中基本读取和写入文件,所以这是可以通过编程解决的原因。

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());

到所有文件路径, new Path(element.path) code>,新目录(newLocation);

strong>

但是这是非常低效的,因为整个文件必须由系统读入并写回一个文件。您可以只需使用shell进程由Dart产生,以便照顾的过程:

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", ...])

这篇关于是否有一个内置函数来复制Dart中的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆