Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Zip multiple files

Zip multiple files

Scheduled Pinned Locked Moved C#
help
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JustRonald
    wrote on last edited by
    #1

    Hi, I created an application which will zip .txt files into .zip For each textfile I selected in my listbox it creates one zip file. But I want to modify it now so all files I select would come in one zip file. This is a part of my form.cs file:

    public Form1()
    {
    InitializeComponent();
    listBox1.SelectionMode = SelectionMode.MultiExtended;
    listBox1.DataSource = ClassFile.GetFiles(@"C:\");
    }

    private void button1_Click(object sender, EventArgs e)
    {
    /* Declaratie */
    ArrayList bestanden;
    string StoragePath;
    string OldFile;
    string NewFile;
    string[] split;
    int i;

    /\* Initialisatie \*/
    bestanden = new ArrayList();
    StoragePath = @"C:\\";
    
    
    /\* Code \*/
    for (i = 0; i < listBox1.SelectedItems.Count; i++)
    {
         split = listBox1.SelectedItems\[i\].ToString().Split('.');
         bestanden.Add(split\[0\]);
    }            
         
    listBox2.Items.Clear();
    
    foreach (string bestand in bestanden)
    {
         OldFile = StoragePath + bestand + ".txt";
         NewFile = StoragePath + bestand + ".zip";
    
         listBox2.Items.Add("Tekst bestand: " + OldFile);
    
         ClassFile.FileToZip(StoragePath, OldFile, NewFile);
    
         if (ClassFile.Overschijven == true)
         {
              listBox2.Items.Add("ZIP conversie succesvol: " + NewFile);
         }
         else
         {
              listBox2.Items.Add("ZIP conversie mislukt: " + OldFile);
         }
    }
    

    }

    This is my class file:

    public ArrayList GetFiles(string dir)
    {
    /* Declaratie */
    ArrayList list;
    DirectoryInfo di;
    FileInfo[] rgFiles;

            /\* Initialisatie \*/
            list = new ArrayList();
            di = new DirectoryInfo(dir);
            rgFiles = di.GetFiles("\*.txt");
    
            /\* Code \*/
            foreach(FileInfo fi in rgFiles)
            {
                list.Add(fi.Name);          
            }
            return list;
        }
    
        public void FileToZip(string zipFileStoragePath, string fileToCompress, string zipFileName)
        {
            // Controle of het bestand wel bestaat
            if (File.Exists(fileToCompress) == false)
            {
                MessageBox.Show("Bestand niet gevonden.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // Controle of het zip bestand al bestaat
                if (File.Exist
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups