Skip to content

Instantly share code, notes, and snippets.

@nemec

nemec/pathlib.cs

Last active Dec 28, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.