简体   繁体   中英

Copy all files to the destination directory in Fake f#make

I want to copy all files in a particular directory to destination directory.
My code is running perfectly but no files are being copied to the destination folder .

I have tried two approaches but no luck :(
Here is my code:

Approach 1:

#r @"packages\FAKE\tools\FakeLib.dll"

open Fake
let buildDir = "D:/MyDir/build/"
let testDir  = "D:/MyDir/test/"

let sourceDir = "D:/Files"

// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)

Target "BuildSetup" (fun _ ->
    !!(sourceDir + "\**\*.txt")
|> Copy testDir)

"Clean"
  ==>"BuildSetup"

RunTargetOrDefault "BuildSetup"

Approach 2 :

#r @"packages\FAKE\tools\FakeLib.dll"
open Fake
let buildDir = "D:/MyDir/build/"
let testDir  = "D:/MyDir/test/"

let sourceDir = "D:/Files"

// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir ;sourceDir]
)

Target "Default" (fun _ ->
trace "Hello World from FAKE"
) 

let additionalFiles = ["D:\Files\new\*.*"]

Target "CopyFiles" (fun _ ->
CopyTo buildDir additionalFiles
)

Target "BuildSetup" (fun _ ->
    !!("D:\Files\new\*.txt")
|> Copy buildDir)


"Clean"
  //==> "Clean"
  //==> "BuildStep"
  ==> "CopyFiles"

RunTargetOrDefault "BuildSetup"

this code is being run , but files are not copied to the destination folder .

please tell me root cause of the problem , I am new to fake .

The below is a working example:

#r "./packages/FAKE/tools/FakeLib.dll"

open Fake

let source = "C:/test/source"
let additionalFilesDir = "C:/test/additional"
let dest  = "C:/test/dest/"

Target "Clean" (fun _ ->
    CleanDirs [dest]
)

Target "Default" (fun _ ->
    trace "Hello World from FAKE"
)

Target "CopyDirectory" (fun _ ->
    CopyDir (directory dest) source allFiles
)

Target "CopyAdditionalFiles" (fun _ ->
    !!(additionalFilesDir @@ "**/*")
    --(additionalFilesDir @@ "**/*.txt") //exclude '.txt' files
    |> Copy dest

    //copy will NOT fail if directory not existing
    if not <|directoryExists additionalFilesDir then
        traceError ("additionalFilesDir doesn't exist:" + additionalFilesDir)
)


"Clean"
    ==> "CopyDirectory"
    ==> "CopyAdditionalFiles"
    ==> "Default"

RunTargetOrDefault "Default"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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