Sss
Sss

Reputation: 1529

how to know the contents of tar file

I have to clear one doubt regarding the tar file..Even this documentation was of big help for me (How to parse a tar file in C++)....

But still some thing to ask..Is there any way to know the "FileType" in the .tar file. Here in the given data by you we just have the contents of file..But suppose if i want to get only a particular file like any .html file (If present in tar file) ..Then is there any way to do that ???

I know that i need to deal with file-type(.html in my case)..How could i know that if there is any .html file present in the tar file ??

Upvotes: 1

Views: 214

Answers (2)

Sss
Sss

Reputation: 1529

@David i have done it you can see the code below if yo uwish to do so-

char* StartPosition;
    //char *check;
    size_t skip= 0;
    char HtmlFileContents [200000];
    char contents [8000];
    do
    { 
            int SizeOfFile = CreateOctalToInteger(&buffer[skip+124],11);
            size_t distance= ((SizeOfFile%512) ? SizeOfFile + 512 - (SizeOfFile%512) : SizeOfFile );
            skip += distance + 512;
            memcpy(contents,&buffer[skip],100);
            if (StartPosition=strstr(contents,".html"))
            {
                MessageBox(m_hwndPreview,L"finally string is copied",L"BTN WND6",MB_ICONINFORMATION);
                int SizeOfFile = CreateOctalToInteger(&buffer[skip+124],11);
                memcpy(HtmlFileContents,&buffer[skip+512],SizeOfFile);
                break;
            }


    }
    while(strcmp(contents,".html") != NULL);

here now we can have html file or any file of our wish using the file extension of that file. My code will copy the contents of that file and can store in HtmlFileContents(in my case- it may be anything according to your wish).

Upvotes: 1

David Hoelzer
David Hoelzer

Reputation: 16379

Frankly, I'd probably shell out and parse the results of "tar -tvf tarfile.tar" rather than write a tar parser from scratch. You can then process the results searching for whichever file it is that you're trying to identify.

Upvotes: 0

Related Questions