Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.IO.Compression;
- namespace ConsoleApplication {
- class Program
- {
- static void Main(string[] args)
- {
- string targetDir = string.Empty;
- if(args.Length == 1){
- targetDir = args[0];
- }
- if(IsValidPath(targetDir, false)){
- string fileOut = new DirectoryInfo(targetDir).Name + ".zip";
- try{
- string _fileout = fileOut;
- ZipFile.CreateFromDirectory(targetDir, fileOut);
- Console.WriteLine("\n Zip archive was successfully created.");
- }catch(Exception exWhileZipping){
- Console.Write("\n {0}", exWhileZipping.Message);
- }
- }else{
- Console.Write("\n Invalid path: {0}", targetDir);
- }
- }
- public static bool IsValidPath(string path, bool allowRelativePaths = false)
- {
- bool isValid = true;
- try
- {
- string fullPath = Path.GetFullPath(path);
- if (allowRelativePaths)
- {
- isValid = Path.IsPathRooted(path);
- }
- else
- {
- string root = Path.GetPathRoot(path);
- isValid = string.IsNullOrEmpty(root.Trim(new char[] { '\\', '/' })) == false;
- }
- }
- catch(Exception ex)
- {
- isValid = false;
- Console.WriteLine("\n " + ex.Message);
- }
- return isValid;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement