3 people like it.
Like the snippet!
Copy a directory of files
Copies a directory of files. Based on code from http://msdn.microsoft.com/en-us/library/bb762914.aspx
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
|
let rec directoryCopy srcPath dstPath copySubDirs =
if not <| System.IO.Directory.Exists(srcPath) then
let msg = System.String.Format("Source directory does not exist or could not be found: {0}", srcPath)
raise (System.IO.DirectoryNotFoundException(msg))
if not <| System.IO.Directory.Exists(dstPath) then
System.IO.Directory.CreateDirectory(dstPath) |> ignore
let srcDir = new System.IO.DirectoryInfo(srcPath)
for file in srcDir.GetFiles() do
let temppath = System.IO.Path.Combine(dstPath, file.Name)
file.CopyTo(temppath, true) |> ignore
if copySubDirs then
for subdir in srcDir.GetDirectories() do
let dstSubDir = System.IO.Path.Combine(dstPath, subdir.Name)
directoryCopy subdir.FullName dstSubDir copySubDirs
|
val directoryCopy : srcPath:string -> dstPath:string -> copySubDirs:bool -> unit
Full name: Script.directoryCopy
val srcPath : string
val dstPath : string
val copySubDirs : bool
val not : value:bool -> bool
Full name: Microsoft.FSharp.Core.Operators.not
namespace System
namespace System.IO
type Directory =
static member CreateDirectory : path:string -> DirectoryInfo + 1 overload
static member Delete : path:string -> unit + 1 overload
static member EnumerateDirectories : path:string -> IEnumerable<string> + 2 overloads
static member EnumerateFileSystemEntries : path:string -> IEnumerable<string> + 2 overloads
static member EnumerateFiles : path:string -> IEnumerable<string> + 2 overloads
static member Exists : path:string -> bool
static member GetAccessControl : path:string -> DirectorySecurity + 1 overload
static member GetCreationTime : path:string -> DateTime
static member GetCreationTimeUtc : path:string -> DateTime
static member GetCurrentDirectory : unit -> string
...
Full name: System.IO.Directory
System.IO.Directory.Exists(path: string) : bool
val msg : string
Multiple items
type String =
new : value:char -> string + 7 overloads
member Chars : int -> char
member Clone : unit -> obj
member CompareTo : value:obj -> int + 1 overload
member Contains : value:string -> bool
member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
member EndsWith : value:string -> bool + 2 overloads
member Equals : obj:obj -> bool + 2 overloads
member GetEnumerator : unit -> CharEnumerator
member GetHashCode : unit -> int
...
Full name: System.String
--------------------
System.String(value: nativeptr<char>) : unit
System.String(value: nativeptr<sbyte>) : unit
System.String(value: char []) : unit
System.String(c: char, count: int) : unit
System.String(value: nativeptr<char>, startIndex: int, length: int) : unit
System.String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
System.String(value: char [], startIndex: int, length: int) : unit
System.String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: System.Text.Encoding) : unit
System.String.Format(format: string, [<System.ParamArray>] args: obj []) : string
System.String.Format(format: string, arg0: obj) : string
System.String.Format(provider: System.IFormatProvider, format: string, [<System.ParamArray>] args: obj []) : string
System.String.Format(format: string, arg0: obj, arg1: obj) : string
System.String.Format(format: string, arg0: obj, arg1: obj, arg2: obj) : string
val raise : exn:System.Exception -> 'T
Full name: Microsoft.FSharp.Core.Operators.raise
Multiple items
type DirectoryNotFoundException =
inherit IOException
new : unit -> DirectoryNotFoundException + 2 overloads
Full name: System.IO.DirectoryNotFoundException
--------------------
System.IO.DirectoryNotFoundException() : unit
System.IO.DirectoryNotFoundException(message: string) : unit
System.IO.DirectoryNotFoundException(message: string, innerException: exn) : unit
System.IO.Directory.CreateDirectory(path: string) : System.IO.DirectoryInfo
System.IO.Directory.CreateDirectory(path: string, directorySecurity: System.Security.AccessControl.DirectorySecurity) : System.IO.DirectoryInfo
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
val srcDir : System.IO.DirectoryInfo
Multiple items
type DirectoryInfo =
inherit FileSystemInfo
new : path:string -> DirectoryInfo
member Create : unit -> unit + 1 overload
member CreateSubdirectory : path:string -> DirectoryInfo + 1 overload
member Delete : unit -> unit + 1 overload
member EnumerateDirectories : unit -> IEnumerable<DirectoryInfo> + 2 overloads
member EnumerateFileSystemInfos : unit -> IEnumerable<FileSystemInfo> + 2 overloads
member EnumerateFiles : unit -> IEnumerable<FileInfo> + 2 overloads
member Exists : bool
member GetAccessControl : unit -> DirectorySecurity + 1 overload
member GetDirectories : unit -> DirectoryInfo[] + 2 overloads
...
Full name: System.IO.DirectoryInfo
--------------------
System.IO.DirectoryInfo(path: string) : unit
val file : System.IO.FileInfo
System.IO.DirectoryInfo.GetFiles() : System.IO.FileInfo []
System.IO.DirectoryInfo.GetFiles(searchPattern: string) : System.IO.FileInfo []
System.IO.DirectoryInfo.GetFiles(searchPattern: string, searchOption: System.IO.SearchOption) : System.IO.FileInfo []
val temppath : string
type Path =
static val DirectorySeparatorChar : char
static val AltDirectorySeparatorChar : char
static val VolumeSeparatorChar : char
static val InvalidPathChars : char[]
static val PathSeparator : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
System.IO.Path.Combine([<System.ParamArray>] paths: string []) : string
System.IO.Path.Combine(path1: string, path2: string) : string
System.IO.Path.Combine(path1: string, path2: string, path3: string) : string
System.IO.Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
property System.IO.FileInfo.Name: string
System.IO.FileInfo.CopyTo(destFileName: string) : System.IO.FileInfo
System.IO.FileInfo.CopyTo(destFileName: string, overwrite: bool) : System.IO.FileInfo
val subdir : System.IO.DirectoryInfo
System.IO.DirectoryInfo.GetDirectories() : System.IO.DirectoryInfo []
System.IO.DirectoryInfo.GetDirectories(searchPattern: string) : System.IO.DirectoryInfo []
System.IO.DirectoryInfo.GetDirectories(searchPattern: string, searchOption: System.IO.SearchOption) : System.IO.DirectoryInfo []
val dstSubDir : string
property System.IO.DirectoryInfo.Name: string
property System.IO.FileSystemInfo.FullName: string
More information