Extracting Files

This is a discussion on Extracting Files within the C Programming forums, part of the General Programming Boards category; Hi there, I am trying to write a file archiving utility, and the archiving has gone well. However i am ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    Question Extracting Files

    Hi there,

    I am trying to write a file archiving utility, and the archiving has gone well. However i am trying to extract and i am having trouble. I was hoping someone could offer some help as i am very much a novice at C#.

    Inside my archived file, i have a header for the file archived, then the contents of that file file, then a file footer, then a header for the second file and the contents and then a header, then another header etc.

    For the extraction of the files, i want to read the first header file and create a file of the same name and then read from the archived file, and write to the new existing file the contents. I then want to read the header file for the second file, creating a second file and reading and writing it's contents to the second file created. I want to only use read(), write(), open(), close(), lseek() etc.

    Hopefully this makes sense
    If not, please ask for more information

    Help will be much appreciated

    Thank you

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    C# + read(), write(), and open() = confused.

    Is there a valid reason to use *nix-specific file handling functions?

    I fail to see how you can do part 1 ("archiving") and not realize that part 2 ("extracting") is the same as part 1, with the read coming from the archive and the write going to the file instead of the other way around and calling decompress() instead of compress().

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    Question

    I understand what your saying, but i'm still having trouble.

    When i am extracting the files from the 'archived' file, i will not know what files are in there. Therefore i have to seek through the 'archived' file to find separations between how ever many files there are in the 'archived' file; hence the header and footer of separating each file.
    If i give the 'archived' file to someone with instructions of how to extract them, how will they know what files are within it.


    My archiving method of files into the 'archived' at the command prompt is:

    ubuntu@ubuntu:~$ ./program file1 file2 file3 archivedfile.txt

    And mu extraction method id as follows:

    ubuntu@ubuntu:~$ ./program archivedfile.txt

    Therefore each method is separated by an if statement:

    if (argc >2)
    archive..

    if (argc == 2)
    extract..

    Does that make sense?
    As i said i am very much a novice to C#

    Thanks

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by man_of _my_word View Post
    When i am extracting the files from the 'archived' file, i will not know what files are in there. Therefore i have to seek through the 'archived' file to find separations between how ever many files there are in the 'archived' file; hence the header and footer of separating each file.
    If i give the 'archived' file to someone with instructions of how to extract them, how will they know what files are within it.
    Because the header will tell them, or so you said before.

    Quote Originally Posted by man_of _my_word View Post
    As i said i am very much a novice to C#

    Thanks
    Are you really planning to use C#? Really? Really really?

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by man_of _my_word View Post
    I understand what your saying, but i'm still having trouble.

    When i am extracting the files from the 'archived' file, i will not know what files are in there. Therefore i have to seek through the 'archived' file to find separations between how ever many files there are in the 'archived' file; hence the header and footer of separating each file.
    If i give the 'archived' file to someone with instructions of how to extract them, how will they know what files are within it.


    My archiving method of files into the 'archived' at the command prompt is:

    ubuntu@ubuntu:~$ ./program file1 file2 file3 archivedfile.txt

    And mu extraction method id as follows:

    ubuntu@ubuntu:~$ ./program archivedfile.txt

    Therefore each method is separated by an if statement:

    if (argc >2)
    archive..

    if (argc == 2)
    extract..

    Does that make sense?
    As i said i am very much a novice to C#

    Thanks
    So...your program created the archive, but can't unpack it? Well, have you tried printing the output as each data structure is traversed to verify that you're reading it properly?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    Question

    Quote Originally Posted by Sebastiani View Post
    So...your program created the archive, but can't unpack it? Well, have you tried printing the output as each data structure is traversed to verify that you're reading it properly?
    Yes, i can create the archive, but yes, i cannot unpack it. I just cant get my head around how to write the code to seek through the file and extract it to newly created file according to the headers within the 'archived' file.
    The archiving process is reading perfectly, but i have not written the code to extract yet, hence why i am asking for help?

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    How do you know the files are successfully archived? Do you have sufficient information to extract a file? Why are you trying to seek if you don't allow extraction of individual files? What does your header and footer look like? How do you determine what are header/footer contents and what are file contents in your archive? Some/all of your code might be very helpful here.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by man_of _my_word View Post
    Yes, i can create the archive, but yes, i cannot unpack it. I just cant get my head around how to write the code to seek through the file and extract it to newly created file according to the headers within the 'archived' file.
    The archiving process is reading perfectly, but i have not written the code to extract yet, hence why i am asking for help?
    Well, the code to extract it shouldn't be much different from that used to create it, I would think, eg: instead of writing a "length" field, you're reading it, and instead of writing that many bytes, you're reading it (or skipping it, using a seek operation), etc. If it's the open/lseek/etc API's that you're having trouble with, you could simply create a demo project to practice using them properly, I guess.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by man_of _my_word View Post
    The archiving process is reading perfectly, but i have not written the code to extract yet, hence why i am asking for help?
    You should be asking for help AFTER you've tried coding it yourself, not before.

    I don't understand how you could possibly design an archive format without complete knowledge of how the data is stored inside and hence how to pack and unpack it. Do you simply not know what API calls to make?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-11-2009, 07:45 AM
  2. Header files and multiple definitions
    By sjweinberg in forum C++ Programming
    Replies: 16
    Last Post: 07-17-2009, 06:59 PM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 05:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21