using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; using System.IO; using ICSharpCode.SharpZipLib.Zip;
namespace createzip { public partial class createzip : ServiceBase { public createzip() { InitializeComponent(); }
protected override void OnStart(string[] args) { if (args.Length < 2) { //DirectoryInfo d = new DirectoryInfo("E:\\zipped files\\R_23122013"); /* I guess my mistake is lying in below 2 lines */ ZipFile z = new ZipFile("E:\\zipped files\\R_23122013"); Console.WriteLine(z);//"E:\\R_23122013" return; } if (!Directory.Exists(args[0])) { Console.WriteLine("cannot find directory '(0)'", args[0]); return; } try { string[] filenames = Directory.GetFiles(args[0]); using (ZipOutputStream s = new ZipOutputStream(File.Create(args[1]))) { s.SetLevel(9); byte[] buffer = new byte[4096]; foreach (string file in filenames) { ZipEntry entry = new ZipEntry(Path.GetFileName(file)); entry.DateTime = DateTime.Now; s.PutNextEntry(entry); using (FileStream fs = File.OpenRead(file)) { int sourcebytes; do { sourcebytes = fs.Read(buffer, 0, buffer.Length); s.Write(buffer, 0, sourcebytes); } while (sourcebytes > 0); } } s.Finish(); s.Close(); } } catch (Exception ex) { Console.WriteLine("Exception during processing {0}", ex); } } protected override void OnStop() { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)