이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to read zipped fies without open them
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a bunch of zipped rain radar files which are raster. I cannot open all of them, becasue they are many and large. Is there a way to read them without opening them? I would like to read the by the date in the file name and sum them.
Thank you in advance
답변 (1개)
Walter Roberson
2021년 5월 6일
댓글 수: 14
Shulamit Nussboim
2021년 5월 6일
Thank you, but zipped file names ending are not zip but asc:
e.g.: 'RMcomp_201910150040.asc'
Walter Roberson
2021년 5월 6일
In that first link, in the code section "UPDATED VERSION FOR SCANNING A FOLDER FOR ZIP FILES AND PROCESS ALL OF THEM", change the .zip to .asc
Shulamit Nussboim
2021년 5월 9일
편집: Shulamit Nussboim
2021년 5월 9일
I tried the code and I have two problems:
- When I run the line
zipFile = org.apache.tools.zip.ZipFile(fullfile(zipfolder,zipfiles(i).name));
I get this:
Java exception occurred:
java.util.zip.ZipException: archive is not a ZIP archive
at org.apache.tools.zip.ZipFile.positionAtEndOfCentralDirectoryRecord(ZipFile.java:774)
at org.apache.tools.zip.ZipFile.positionAtCentralDirectory(ZipFile.java:710)
at org.apache.tools.zip.ZipFile.populateFromCentralDirectory(ZipFile.java:455)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:216)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:191)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:163)
2. I cannot run the code on a folder with a lagre number of files. The current folder says:" There are too many entries to display. Click the search botton in the adreess bar to reduce the number of entries".
Walter Roberson
2021년 5월 9일
That file extension tends to suggest that the file is not zip and is instead a ASCII Grid radar file.
https://www.mathworks.com/help/map/ref/arcgridread.html
Shulamit Nussboim
2021년 5월 9일
편집: Shulamit Nussboim
2021년 5월 9일
Yes, but it is zipped (ending is asc.gz). If I use 'readgeoraster' for the uzipped file it reads it, but I have a bunch of files and I cannot open each one but I want to run over the directory and read it in a loop. The names are (the gz ending does not appear in the folder but only in the current folder in the matlab):
RMcomp_201910150000.asc
RMcomp_201910150010.asc
RMcomp_201910150020.asc
RMcomp_201910150030.asc
etc.
I want to read/ extract data and sum them, and to leave all the files zipped after I extracted from them the data, because they are very large.
Thank you for you help
Walter Roberson
2021년 5월 9일
I am confused about whether the zip files do or do not end in .gz .
If the zip files end in .gz then In that first link, in the code section "UPDATED VERSION FOR SCANNING A FOLDER FOR ZIP FILES AND PROCESS ALL OF THEM", change the .zip to .gz
Shulamit Nussboim
2021년 5월 9일
편집: Shulamit Nussboim
2021년 5월 9일
Thank you, I will tried. It Shows me again:
Error using unzipascfile (line 7)
Java exception occurred:
java.util.zip.ZipException: archive is not a ZIP archive
at org.apache.tools.zip.ZipFile.positionAtEndOfCentralDirectoryRecord(ZipFile.java:774)
at org.apache.tools.zip.ZipFile.positionAtCentralDirectory(ZipFile.java:710)
at org.apache.tools.zip.ZipFile.populateFromCentralDirectory(ZipFile.java:455)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:216)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:191)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:163)
The files are zipped and appear ending as .asc,gz. tried to change to gz and asc.gz and it did not work (changed on the following line, instead of zip):
zipfiles = dir([zipfolder,'\*.zip']);
and it did not work.
Maybe my explenation is not well understood. I will try another approach and thank you for the attention and the time you dedicated.
Walter Roberson
2021년 5월 9일
The files are zipped and appear ending as .asc,gz
Is that a comma before the gz ? If so then
zipfiles = dir([zipfolder,'\*,gz']);
Are you using Windows? Or are you using linux or Mac? If you are using Linux or Mac, then try
!file RMcomp_201910150000.asc.gz
to see what the operating system can guess about what kind of file it is. (This will not work for Windows unless you install the Linux subsystem.)
Shulamit Nussboim
2021년 5월 10일
Sorry, it was a typing mistake. It is .gz and I use windows 10.
I tried
zipfiles = dir([zipfolder,'\*.gz']);
but still it did not work and starting the first iteration the error apeared again:
Error using unzipascfile (line 7)
Java exception occurred:
java.util.zip.ZipException: archive is not a ZIP archive
at org.apache.tools.zip.ZipFile.positionAtEndOfCentralDirectoryRecord(ZipFile.java:774)
at org.apache.tools.zip.ZipFile.positionAtCentralDirectory(ZipFile.java:710)
at org.apache.tools.zip.ZipFile.populateFromCentralDirectory(ZipFile.java:455)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:216)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:191)
at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:163)
Maybe I have to look fore a different solution. Thank you
Walter Roberson
2021년 5월 10일
편집: Walter Roberson
2021년 5월 10일
Well, you can use gunzip() to uncompress the file, but that expand the file on disk. There is no tool that can "stream" an unzipped gz file into arcgridread() . You would have to merge the code for gunzip and arcgridread(), which would take a fair bit of modification.
It would probably be easier to loop gunzip one file at a time, read it, delete the unzipped version .
Shulamit Nussboim
2021년 5월 10일
Yes, thank you. I find this direction usefull. Do you have any idea why the code did not work for me?
Walter Roberson
2021년 5월 10일
org.apache.tools.zip.ZipFile() works with .zip files but .gz files are a slightly different format. gunzip() knows how to read them.
참고 항목
카테고리
Help Center 및 File Exchange에서 Cloud File Storage에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)