PathLib Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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