Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

File Segmenter

0.00/5 (No votes)
31 Mar 2001 1  
This class creates from 1-9 segments of a single file which can be then desgmented.Useful for moving larger file on floppies.

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

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