untar selcted files from archive

3 views (last 30 days)
Mike
Mike on 3 Jan 2012
I have a 'test.tar.gz' file, which contains, for example, 10 files. They are '001.nc', '002.nc', ..., '010.nc'.
I can use 'untar' to uncmpress all 10 files into folder. But if I only need one file in the archive, say, '002.nc', and untarring all files will be a waste time, especially when the tar file is extremely big.
Is there any way I can select which files to untar and skip the rest?
btw, I tried to edit the 'untar' function, but couldn't find a place where I can add such an input argument.
Is there anybody who has any ideas?
Thank you a lot. Mike

Answers (1)

Walter Roberson
Walter Roberson on 3 Jan 2012
It appears to me that if you went in to untar.m and modified getNextEntry, you could have it check the received name and go back to do tarInStream.getNextEntry() if it did not match.
Myself, I wouldn't bother doing that, but then I'm using Unix systems where I can gzip and pipe that in to tar -x specifying the names I want to retrieve.
  2 Comments
Mike
Mike on 3 Jan 2012
sounds like a very doable solution. But could you please explain it in a little more detail? I am not very sure that I can make the change correctly...
For example, I only want to extract files that has a specific name (e.g., '004.nc'). How should I modify the 'untar.m' code?
Thank you.
Walter Roberson
Walter Roberson on 3 Jan 2012
Modify that routine to use a "while true" loop. Have the "entry =" assignment first thing inside that loop. Validate the entry like it shows. Add an "elseif isempty(entry)" to the validation, and break out of the loop when it occurs; then "else", getEntryName(entry); compare the returned entry name to the file names you are looking for, and if it is one of them then break out of the loop (and otherwise allow the loop to continue so it will get the next entry)

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!