how can i extract a file in c ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moroccanplaya
    New Member
    • Jan 2011
    • 80

    #1

    how can i extract a file in c ?

    ok i have created a program that lets the user create a file/archive and then copy files into that file/archive

    so how would you go on about extracting the files?

    i know you have to create another file where the record is kept where the sizes of the files i just don't know how to put it to work
  • tdlr
    New Member
    • Jan 2011
    • 22

    #2
    It would help to know, how exactly you are "copying the files into the archive". If you do a simple binary append, you could just reserve the first X bytes of the file for an integer Y representing the header length, followed by a file header which is exactly Y bytes long. Store the file names and their starting byte positions in the header. Then, if you want to "unpack" a file, look up its position in the header, and copy the bytes from the starting position to the beginning of the next file to a new file called whatever the original filename was and then you're done. I know that this is a really primitive approach and there are some issues with this way, but as a general idea, it is a concept to start and work with.

    Comment

    • moroccanplaya
      New Member
      • Jan 2011
      • 80

      #3
      the program that i have already lets the user create the archive which basically is just a file, then the user can add files into the archive, which makes it into one big file the problem is how to extract that big file for example i want to extract file 5 out 10 files that been copied i just cant get my head round doing it. so does it mean i have to store the file size and the file name within the archve?

      Comment

      • tdlr
        New Member
        • Jan 2011
        • 22

        #4
        Of course, this would be the one and only way to go. You may have a look at how it's done with the "tar" format, which is basically just a container format: http://en.wikipedia.org/wiki/Tar_%28...Format_details

        Comment

        • moroccanplaya
          New Member
          • Jan 2011
          • 80

          #5
          ok thanks so how would i go on creating a metadata in c to store all the file details or shall i just store it in a text file?

          Comment

          Working...