Skip to content

Instantly share code, notes, and snippets.

@nemec
Last active December 28, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemec/7462757 to your computer and use it in GitHub Desktop.
Save nemec/7462757 to your computer and use it in GitHub Desktop.
PathLib Sample
// Example showing the utility of
// https://github.com/nemec/pathlib
// Given an input and output directory, zip the input directory
// and drop it into the output directory. The zip file should
// have the same name as the input directory (plus .zip extension)
var dirToZip = new PureNtPath(@"C:\Users\Admin\MyPhotos");
// These work too, paths are normalized when created from strings!
//var dirToZip = new PureNtPath(@"C:\Users\Admin\MyPhotos\");
//var dirToZip = new PureNtPath(@"C:/Users/Admin/MyPhotos");
//var dirToZip = new PureNtPath(@"C:\Users/Admin\MyPhotos/");
var outputDir = new PureNtPath(@"G:\Archive");
var zipFilename = dirToZip.WithExtension("zip").Filename;
var outputPath = outputDir.Join(zipFilename); // G:\Archive\MyPhotos.zip
var bytes = new ZipFile(dirToZip.ToString()).GetBytes(); // Handwaving. Pick your favorite Zip library.
File.WriteAllBytes(outputPath.ToString(), bytes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment