Skip to content

Commit

Permalink
Add Shell.copyFilesWithSubFolder, fixes #1937
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed May 19, 2018
1 parent b699fee commit f87aad6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* BUGFIX: Some issues when running latest `dotnet cli` via the Fake.DotNet.Cli module.
* BUGFIX: Fake.Core.Xml changed DOCTYPE - https://github.com/fsharp/FAKE/issues/1692
* ENHANCEMENT: Add API to set the build state - https://github.com/fsharp/FAKE/issues/1936
* ENHANCEMENT: Add `Shell.copyFilesWithSubFolder` to copy files while keeping relative directories in place - https://github.com/fsharp/FAKE/issues/1937


## 5.0.0-rc014 - 2018-05-20

Expand Down
20 changes: 20 additions & 0 deletions src/app/Fake.IO.FileSystem/Shell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ module Shell =
/// - `files` - The orginal file names.
let copyFiles target files = copy target files

/// Copies the given glob-matches into another directory by leaving relative paths in place based on the globbing base-directory
///
/// ## Sample
///
/// !! "**/My*Glob*.exe"
/// |> GlobbingPattern.setBaseDir "baseDir"
/// |> Shell.copyFilesWithSubFolder "targetDir"
///
let copyFilesWithSubFolder targetDir (files:IGlobbingPattern) =
let baseFull = (Path.GetFullPath files.BaseDirectory).TrimEnd [|'/';'\\'|]
for item in files do
let info = FileInfo.ofPath item
let itemSpec =
// first get relative path from the globbing
let relative = (info.FullName.Substring (baseFull.Length+1))
relative
let parent = Path.GetDirectoryName (targetDir</>itemSpec)
Directory.ensure parent
File.Copy(item, targetDir</>itemSpec, true)


/// Copies a directory recursivly. If the target directory does not exist, it will be created.
/// ## Parameters
Expand Down

0 comments on commit f87aad6

Please sign in to comment.