Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

.001,.002, ... Part Files Combiner

2.20/5 (10 votes)
4 Oct 20071 min read 1   418  
This program simply generates a batch file that you can extract your .00x files
Title:       .001, .002 Files Combiner
Author:      Ali Tahouri
Email:       ali_2004t@yahoo.com
Language:    C#
Platform:    Windows
Description: This program simply generates a batch file that you can extract your .00x files
Section      General C#
SubSection   Files and Folders
Screenshot - combiner.jpg

Introduction

I download a lot of files everyday (5 gigs per day) and sometimes I see some files like these (specially for the films or big files):

Godfather_CD2_W-BB_BrAd.avi.001
Godfather_CD2_W-BB_BrAd.avi.002
Godfather_CD2_W-BB_BrAd.avi.003
Godfather_CD2_W-BB_BrAd.avi.004
Godfather_CD2_W-BB_BrAd.avi.005
Godfather_CD2_W-BB_BrAd.avi.006
Godfather_CD2_W-BB_BrAd.avi.007
Godfather_CD2_W-BB_BrAd.avi.008

extracting these files are a little complex. you can use winrar to compress them once and then extract them from the new compressed file but it is very timeconsuming! with this program you can easily combine these type of files!

Using the code

For using this program you should do the followings :

0- copy the Combiner.exe to the folder that you have some .001, .002, ... files.

1- copy one of your part file's name to the clipboard. for example I copy the file named : "Godfather_CD2_W-BB_BrAd.avi.001"

2- Open the program (It automatically paste the file name in the correct place!). you write the filename yourself.

3- Enter the number of parts (in this cace I sould enter 8)

4- Press the Generate button! then a .bat file will create ! ("Godfather_CD2_W-BB_BrAd.avi.bat" in this case!) if you run that .bat file then your files will combined and the main file would created! ("Godfather_CD2_W-BB_BrAd.avi" in this case!)

THE CODE

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace Combiner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = Clipboard.GetText();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.ToString() != "")
            {
                try
                {
                    string s = textBox1.Text.ToString();
                    string fileName = s.Substring(0, s.Length - 4);
                    int x = Convert.ToInt16(textBox2.Text.ToString());
                    FileInfo f = new FileInfo(fileName + ".bat");
                    StreamWriter w = f.CreateText();
                    w.WriteLine("Copy /b \"" + fileName + ".001" + "\" \"" + fileName + "\"\n");
                    for (int i = 2; i <= x; i++)
                        w.WriteLine("Copy /b \"" + fileName + "\" + \"" + fileName + "." + ((i >= 100) ? "" : "0") + ((i < 100 && i >= 10) ? "" : "") + ((i < 10) ? "0" : "") + i.ToString() + "\"\n");
                    w.Close();
                    MessageBox.Show("The file \"" + fileName + ".bat\" created successfully!\nuse it to extract your file!");
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.ToString());
                }
            }
            else
            { MessageBox.Show("enter the number of part files!"); }
        }             
    }
}
Special thanks to you for using this product!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here