4 people like it.

Unzip from multiple zip files in one pass

If you have a directory containing multiple zip files, unzip them all in one pass. (Requires .NET 4.5)

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
#if INTERACTIVE
#r @"System.IO.Compression"
#r @"System.IO.Compression.FileSystem"
#endif

open System.IO
open System.Net
open System.IO.Compression

// Extract the contents of multiple zip archives in one pass.
//
// Eg. ExtractAll @"C:\Data\Corpora\GoogleNGrams\Compressed" @"C:\Data\Corpora\GoogleNGrams\Uncompressed"
//
let ExtractAll sourceDir targetDir =
    Directory.EnumerateFiles(sourceDir, "*.zip")
    |> Seq.iter (fun zipPath -> printfn "Uncompressing %s" (Path.GetFileName(zipPath))
                                let archive = ZipFile.Open(zipPath, ZipArchiveMode.Read)
                                archive.ExtractToDirectory(targetDir))
namespace System
namespace System.IO
namespace System.Net
namespace System.IO.Compression
val ExtractAll : sourceDir:string -> targetDir:string -> unit

Full name: Script.ExtractAll
val sourceDir : string
val targetDir : string
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
Directory.EnumerateFiles(path: string) : System.Collections.Generic.IEnumerable<string>
Directory.EnumerateFiles(path: string, searchPattern: string) : System.Collections.Generic.IEnumerable<string>
Directory.EnumerateFiles(path: string, searchPattern: string, searchOption: SearchOption) : System.Collections.Generic.IEnumerable<string>
module Seq

from Microsoft.FSharp.Collections
val iter : action:('T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iter
val zipPath : string
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
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
Path.GetFileName(path: string) : string
val archive : ZipArchive
type ZipFile =
  static member CreateFromDirectory : sourceDirectoryName:string * destinationArchiveFileName:string -> unit + 2 overloads
  static member ExtractToDirectory : sourceArchiveFileName:string * destinationDirectoryName:string -> unit + 1 overload
  static member Open : archiveFileName:string * mode:ZipArchiveMode -> ZipArchive + 1 overload
  static member OpenRead : archiveFileName:string -> ZipArchive

Full name: System.IO.Compression.ZipFile
ZipFile.Open(archiveFileName: string, mode: ZipArchiveMode) : ZipArchive
ZipFile.Open(archiveFileName: string, mode: ZipArchiveMode, entryNameEncoding: System.Text.Encoding) : ZipArchive
type ZipArchiveMode =
  | Read = 0
  | Create = 1
  | Update = 2

Full name: System.IO.Compression.ZipArchiveMode
field ZipArchiveMode.Read = 0
(extension) ZipArchive.ExtractToDirectory(destinationDirectoryName: string) : unit
Raw view Test code New version

More information

Link:http://fssnip.net/jF
Posted:11 years ago
Author:Kit Eason
Tags: compression , zip