Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: copy files with folder structure #558

Closed
otto-gebb opened this issue Oct 9, 2014 · 3 comments
Closed

Suggestion: copy files with folder structure #558

otto-gebb opened this issue Oct 9, 2014 · 3 comments

Comments

@otto-gebb
Copy link
Contributor

The existing function CopyFileIntoSubFolder doesn't allow one to specify the base directory.

Probably it's just me, but I have found it hard to do the following with FAKE.
Let . be the current directory.
Copy .\a\b\source\**\*.* to .\destination preserving the folder structure from .\a\b\source.

I suggest adding a function that does this. Something like the following.

    let CopyFileToSubFolder baseDir target fileName = 
        let relative = (ProduceRelativePath (FullName baseDir) fileName).TrimStart '.'
        let fi = fileInfo fileName
        let targetName = target + relative
        let target = fileInfo targetName
        ensureDirExists target.Directory
        logVerbosefn "Copy %s to %s" fileName targetName
        fi.CopyTo(targetName, true) |> ignore

    let CopyWithSubfoldersTo target (includes:seq<FileIncludes>) =
        let copyFiles dir inc = Seq.iter (CopyFileToSubFolder dir target) inc
        Seq.iter (fun inc -> copyFiles inc.BaseDirectory inc) includes


    [
            !! "a/b/source/**/*.*" |> SetBaseDir "a/b/source"
            !! "x/y/source2/**/*.*" |> SetBaseDir "x/y/source2"
    ]
    |> CopyWithSubfoldersTo "destination"
@forki
Copy link
Member

forki commented Oct 9, 2014

I thought we already have such a thing. Strange.

Please send Pull request. Thanks

2014-10-09 6:55 GMT+02:00 otto-gebb notifications@github.com:

The existing function CopyFileIntoSubFolder doesn't allow one to specify
the base directory.

Probably it's just me, but I have found it hard to do the following with
FAKE.
Let . be the current directory.
Copy .\a\b\source*__.* to .\destination preserving the folder structure
from .\a\b\source.

I suggest adding a function that does this. Something like the following.

let CopyFileToSubFolder baseDir target fileName =
    let relative = (ProduceRelativePath (FullName baseDir) fileName).TrimStart '.'
    let fi = fileInfo fileName
    let targetName = target + relative
    let target = fileInfo targetName
    ensureDirExists target.Directory
    logVerbosefn "Copy %s to %s" fileName targetName
    fi.CopyTo(targetName, true) |> ignore

let CopyWithSubfoldersTo target (includes:seq<FileIncludes>) =
    let copyFiles dir inc = Seq.iter (CopyFileToSubFolder dir target) inc
    Seq.iter (fun inc -> copyFiles inc.BaseDirectory inc) includes


[
        !! "a/b/source/**/*.*" |> SetBaseDir "a/b/source"
        !! "x/y/source2/**/*.*" |> SetBaseDir "x/y/source2"
]
|> CopyWithSubfoldersTo "destination"


Reply to this email directly or view it on GitHub
#558.

@otto-gebb
Copy link
Contributor Author

Allright, will try to refactor the suggested code to remove duplication. My function CopyFileToSubFolder is a copy-paste of the existing CopyFileIntoSubFolder with slight modifications.

@otto-gebb
Copy link
Contributor Author

I am also not sure if I should call FullName on baseDir. Probably we should just mention in the documentation that baseDir must be an absolute path (otherwise ProduceRelativePath calculates the relative path incorrctly)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants