1 people like it.
Like the snippet!
Delete the matching files in a directory
Accepts a directory and wildcard pattern to delete files in a folder
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
|
let rec deleteFiles srcPath pattern includeSubDirs =
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))
for file in System.IO.Directory.EnumerateFiles(srcPath, pattern) do
let tempPath = System.IO.Path.Combine(srcPath, file)
System.IO.File.Delete(tempPath)
if includeSubDirs then
let srcDir = new System.IO.DirectoryInfo(srcPath)
for subdir in srcDir.GetDirectories() do
deleteFiles subdir.FullName pattern includeSubDirs
|
val deleteFiles : srcPath:string -> pattern:string -> includeSubDirs:bool -> unit
Full name: Script.deleteFiles
val srcPath : string
val pattern : string
val includeSubDirs : 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
val file : string
System.IO.Directory.EnumerateFiles(path: string) : System.Collections.Generic.IEnumerable<string>
System.IO.Directory.EnumerateFiles(path: string, searchPattern: string) : System.Collections.Generic.IEnumerable<string>
System.IO.Directory.EnumerateFiles(path: string, searchPattern: string, searchOption: System.IO.SearchOption) : System.Collections.Generic.IEnumerable<string>
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
type File =
static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
static member AppendAllText : path:string * contents:string -> unit + 1 overload
static member AppendText : path:string -> StreamWriter
static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
static member Create : path:string -> FileStream + 3 overloads
static member CreateText : path:string -> StreamWriter
static member Decrypt : path:string -> unit
static member Delete : path:string -> unit
static member Encrypt : path:string -> unit
static member Exists : path:string -> bool
...
Full name: System.IO.File
System.IO.File.Delete(path: string) : unit
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 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 []
property System.IO.FileSystemInfo.FullName: string
More information