Click here to Skip to main content
15,867,686 members
Articles / Desktop Programming / MFC
Article

File Segmenter

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
31 Mar 2001 55.7K   1.2K   13   2
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


Written By
CEO Nerdiacs Pte Ltd
Pakistan Pakistan
I'm a drop out of Chartered Accountancy at ICAP but currently continuing Managment Accountancy at CIMA (UK) but i do programming as hobby.
I usually work in C++, MFC, COM. Other languages/techs I like to play with are C#, VB, ASP, PHP, MSSQL, MySQL, Perl and Flash.
These days I usually play with Open Source Switch/PBX on Linux www.asteriskpbx.com and VoIP products.
I am currently based in Karachi,Pakistan.

Comments and Discussions

 
QuestionWhy a limit? Pin
AlexMarbus1-Mar-01 7:38
AlexMarbus1-Mar-01 7:38 
AnswerRe: Why a limit? Pin
Tili2-Mar-01 11:13
Tili2-Mar-01 11:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.