untar selcted files from archive
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!