Skip to content

Instantly share code, notes, and snippets.

Last active December 28, 2015 07:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
PathLib Sample
// Example showing the utility of
// 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\
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