untar selcted files from archive

조회 수: 8 (최근 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에서 File Compression에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by