The Code Project View our sponsorsGet your new domain name now!Advertise on the CodeProject
Home >> Files & Folders >> General

File Segmenter
By Faizan Naqvi

This class creates from 1-9 segments of a single file which can be then desgmented.Useful for moving larger file on floppies. 
 VC 4-6, Win95-98, NT4, W2K, MFC
 Posted 9 Feb 2001
 Updated 1 Apr 2001
Articles by this author
Send to a friend
Printer friendly version
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
22 users have rated this article. result:
3.14 out of 5.

Sample Image - Segment.jpg

Introduction

Recently I had to copy a file from my computer to my friends computer. It was of 8 MB and was huge for one floppy. So, I created my own software for moving that file.

This software creates 1-9 segments of one file. Creating a segment means making rewriting the same file. The segments are named as xxx.fa1, xxx.fa2 xxx.fa3 ... xxx.fa9. It creates a file like xxx.faz which is the info file which holds information about the original file that was segmented. To desegment a file back to original file, xxx.faz has to be opened and it should be in the same directory where all the other segments are and the original file will be created in the same directory.

How to use

There are only three functions

  1. OpenSegFile()
  2. CreateSegments()
  3. DeSegment()

The concept is that to read a file's length and divide it into as many segments as the user wants by opening it in binary mode and then writing the amount of data to different segments. The CSegFile class supports two progress bars and one static control to provide information. First create your progress bars on a dialog (with ID's IDC_STATIC_INFO, IDC_PROGRESS_BAR, and IDC_PROGRESS_SEG respectively).

To use them, first add code like this into your program:

CSegFile  segFile // better to make it a public member in the header file

// for the static control
segFile.spStatic = (CStatic*) GetDlgItem(IDC_STATIC_INFO);

// for the progress bar (total)
segFile.pProgress=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS_BAR);

//for segmenting bar 
segFile.pSegProgress=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS_SEG);

To open a file you can use code like

CFileDialog fdl(TRUE,NULL,NULL,NULL,NULL,this); 
if (fdl.DoModal()==IDOK) 
{
    CString szFileName; 
    szFileName = fdl.m_ofn.lpstrFile; 
    segFile.OpenSegFile(szFileName); 
    m_currentFile = szFileName; 
    UpdateData(FALSE); 
}

Then you can use this line for segmenting:

segFile.CreateSegments(iSegs); //isegs is the number of segments to do

To desegment a file open the info file xxx.faz and call the the function like this one.

segFile.DeSegment();

I tested it on my computer and my friend's computer. I had no means to check it on NT and win2000. For comments and suggestions contact me at faizan_naqvi@hotmail.com

[Top] Sign in to vote for this article:     PoorExcellent  
Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
 Keyword Filter
 View   Per page   Messages since
New threadMessages 1 to 2 of 2 (Total: 2)First Prev Next Last
Subject 
Author 
Date 
  Why a limit?
AlexMarbus 13:38 1 Mar 01 
  Re: Why a limit?
tili 17:13 2 Mar 01 
Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

Home >> Files & Folders >> General
last updated 1 Apr 2001
Article content copyright Faizan Naqvi, 2001
everything else © CodeProject, 1999-2001.
The Code Project View our sponsorsClick here for Dundas Consulting - experts in MFC, C++, TCP/IP and ASPAdvertise on the CodeProject