untar selcted files from archive

1 次查看(过去 30 天)
Mike
Mike 2012-1-3
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

回答(1 个)

Walter Roberson
Walter Roberson 2012-1-3
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 个评论
Mike
Mike 2012-1-3
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 2012-1-3
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)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by