Click here to Skip to main content
13,299,495 members (69,282 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 29 Jun 2002

File fixing utility

, 29 Jun 2002
Rate this:
Please Sign up or sign in to vote.
FileFixLib is a small file utility to enable precise cutting, splitting and joining of files.


I don't know if this have ever happened to you, but if you are a dialup user like me, downloading huge files can be very time consuming.  Several times it happened while downloading a big file that my PC crashed or get a nice BSOD.  Some download managers can handle this as they have a "rollback" function to eliminate the corrupted last part of the partly downloaded file, sometimes the "rollback" setting isn't big enough and you find yourself with a 300MB+ white elephant.  In the past, I used to use a file splitting program to "split" the file up to the corrupted section, then continue downloading from that point onwards. This wasn't always very handy as sometimes the corrupted section is quite close to the start of the file and you have to practically re-download the entire file.  I landed up the other night in exactly that position and wasn't planning to download another 300MB.

The first requirement I needed was a function to "cut" a piece from the file from a specific start point to a specific end point so that I could recover the part of the file after the error. This would prove equally handy to get the 1st part of the file assuming only one corrupted section.  The Cut function was probably the hardest part, never having worked on files at byte level.  Now it looks pretty elementary, but I could not find any helpful examples and it took some time to make it work exactly like it should.

Now to explain the recovering process. For example, you have a 300MB file with 30KB corrupted at say the 150MB point.

  1. Recover 1st part, i.o.w. "cut" from 0 to 150MB less a couple bytes to make sure.
  2. Recover last part, i.o.w. "cut" from 150MB + 30KB plus a couple bytes to make sure to the end of file.
  3. Resume download on first part till past the start point of the last part.
  4. Re-"cut" 1st part from 0 to start point of last part.
  5. Finally, join the 2 parts.

Secondly, I needed a function to find all the corrupted parts of the file.

[Update: This only really works on CDs, floppy discs and with files on bad sectors] 

This is done with the Scan function. The return value from this function is an multi-dimensional integer array in the form int[x,2] where int[x,0] is start point and int[x,1] the end point of a corrupted part. This was probably the second hardest part, having to catch IOExceptions in a double while loop.

Then I created a library for these functions so I could just interface with it via a command line interface (included in zip) or a windows application.

Lastly I added a the following other helpful functions:

  • Split : to to split files into equal parts, implementation was easy as it just loops through the Cut function.
  • Join: to combine several files together.
  • Some overloads and a counter pointer incase you wanted to track progress in a Windows app or CL app.

The only problem I have it that I do not have a file that has multiple corrupted areas, but in theory it should work. Any suggestions welcome.

Hope this proves helpful, it sure did for me. At the end, I only had to re-download a couple of MB. Other uses include extracting files from a damaged CD.

Quite fun writing my first article.


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


About the Author

Software Developer
South Africa South Africa
No Biography provided

You may also be interested in...


Comments and Discussions

Questionwhy not write a downloader? Pin
v_srinu_26_f3-Nov-05 5:16
memberv_srinu_26_f3-Nov-05 5:16 
GeneralHelp... Pin
Leon11956-Jul-05 10:49
memberLeon11956-Jul-05 10:49 
Generalcool Pin
Taha Zayed14-Sep-04 15:26
memberTaha Zayed14-Sep-04 15:26 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 30 Jun 2002
Article Copyright 2002 by leppie
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid