简体   繁体   English

如何复制文件夹-FAKE F#MAKE

[英]how to copy Folders - FAKE F#MAKE

I am using Copy function of FAKE to copy files from project1 to release folder ,I am using below code : 我正在使用FAKE的Copy功能将文件从project1复制到发布文件夹,我正在使用以下代码:

Target "CopyProject1" (fun _ ->
    !!(buildDir @@ "/_PublishWebsites/Project1/**/*.*")
        |> Copy releaseDir
)

to copy files from Project1 folder to release folder , then all files inside Project1 are being copied to release folder , but I want to maintain folder structure of Project1 inside my release folder , ie I want to copy folders of Project1 to release , Is this possible or I will have to create subfolders inside my release folders and copy one by one .and if there is no such way of doing this then is this possible using custom task? 将文件从Project1文件夹复制到release文件夹,然后将Project1中的所有文件都复制到release文件夹,但是我想在我的release文件夹中维护Project1的文件夹结构,即我想复制Project1的文件夹以发布,这可能吗还是我必须在发布文件夹中创建子文件夹并一一复制。如果没有这种方法,那么可以使用自定义任务吗?

If anyone can help in this regard , that would be really helpful. 如果有人可以在这方面提供帮助,那将是非常有帮助的。

That's available through CopyWithSubfoldersTo . 可通过CopyWithSubfoldersTo获得 It's description says that it: 它的描述说:

Copies several file groups, each represented by a FileIncludes object, to the target folder preserving the folder structure starting from the BaseDirectory of each FileIncludes. 从每个FileIncludes的BaseDirectory开始,将几个文件组复制到目标文件夹,以保留文件夹结构,每个文件组均由FileIncludes对象表示。

The parameters are the same as Copy: 参数与“复制”相同:

Target "CopyProject1" (fun _ ->
    [!!(buildDir @@ "/_PublishWebsites/Project1/**/*.*")]
        |> CopyWithSubfoldersTo releaseDir
)

EDIT 编辑

CopyWithSubfoldersTo works with seq<FileInculdes> while !! CopyWithSubfoldersTo可以与seq<FileInculdes>一起使用!! returns a single FileIncludes . 返回一个FileIncludes This has to be converted to a single element list before it can be used. 必须先将其转换为单个元素列表,然后才能使用。

I used CopyDir function of FAKE , and this is copying directories recursively , we just have to give the folder name and target location where we want to copy folders .Here is the code : 我使用了FAKE的CopyDir函数,这是递归复制目录,我们只需要提供文件夹名称和目标位置即可复制文件夹。这是代码:

Target "CopyFoldersTargetLocation" (fun _ ->
    CopyDir targetDir SourceDir allFiles
)

Since others solutions did not work for my case, here is my homemade solution using basic .NET methods: 由于其他解决方案不适用于我的情况,因此这是使用基本.NET方法的自制解决方案:

let rec copyFilesRecursively (source: DirectoryInfo) (target: DirectoryInfo) =
    source.GetDirectories()
    |> Seq.iter (fun dir -> copyFilesRecursively dir (target.CreateSubdirectory dir.Name))
    source.GetFiles()
    |> Seq.iter (fun file -> file.CopyTo(target.FullName @@ file.Name, true) |> ignore)

Target "CopyProject1" <| fun _ ->
    let source = buildDir @@ "/_PublishWebsites/Project1/"
    let target = releaseDir
    copyFilesRecursively (directoryInfo source) (directoryInfo target)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM