Last active
March 23, 2016 17:38
-
-
Save jwosty/84e1bcc234e7288f9a5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.IO | |
module String = | |
let split chars (s: string) = s.Split chars | |
/// Lazily returns every file and directory that has the given root path as a parent. Directories paths | |
/// occur before their children. | |
let rec getSystemEntriesRec path = | |
seq { yield path | |
for subPath in Directory.GetDirectories path do | |
yield! getSystemEntriesRec subPath | |
yield! Directory.GetFiles path } | |
let relativePath root fullPath = | |
let sep = [|Path.DirectorySeparatorChar|] | |
fullPath |> String.split sep |> Array.skip ((String.split sep root).Length) |> Path.Combine | |
let src, dst = "foo", "bar" | |
src | |
|> getSystemEntriesRec | |
|> Seq.map (fun srcFullPath -> | |
srcFullPath, Path.Combine ([|dst; relativePath src srcFullPath|])) | |
|> Seq.iter (fun (src, dst) -> | |
if File.Exists src then File.Copy (src, dst) | |
else ignore (Directory.CreateDirectory dst)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment