이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
hi ..example.if i have a folder name as 'DATA',inside this subfolder namely A TO Z are ther..in this each folder(A TO Z),many .zip files are ther..i need to fetch all the .zip files inside main folder('DATA'),and extract them to a separate folder.is it possible? any defined function?
채택된 답변
Laurent
2013년 9월 5일
Using the 'dir'-command you can obtain a list of files.
In your case you could use something like:
filelist=dir('DATA/*.zip');
or
filelist=dir('DATA\*.zip');
depending on your OS.
Then filelist will be a struct in which filelist.name has the filenames.
'unzip' can then be used to unzip your files.
댓글 수: 10
sandy
2013년 9월 5일
thanks...here, the .zip files are present inside the folders from A TO Z,not inside DATA itself.. i need to access all the zip file inside them(A TO Z). it like accessing files from all the subfolders(A to Z) of main folder(DATA)
Ah, something like this could then be your solution:
folders=('A':'Z')';
outputfolder='yourfolder';
for ii=1:26
currfold=[folders(ii) '\*.zip'];
currfiles=dir(currfold);
%now do something with these files
for jj=1:length(currfiles)
unzip([folders(ii) '\' currfiles(jj).name],outputfolder);
end
end
sandy
2013년 9월 5일
thanks..it works for A TO Z...but my another question...for example...i am giving the path of folder(YEAR).inside this folder.month folder are present as 01 TO 12,inside each month folder ,date folders are present from 01 to 31,inside each days folder alone zip files present.ineed to access this and unzip..nw its possible??
Yes this is definitely possible. You could use a similar approach for the years and months and put it into extra for-loops around the one from my example.
for kk=1997:2013
{code}
for ll=1:12
{code}
for mm=1:31
{my code}
end
end
end
Of course if not all dates/months/years are there you will have to include a way to check for this.
Also please accept my answer if it was useful for you.
thanks...its works..but if the any day or month folder is not present,what conditions can i use? any predefined function or code ther?
To check if a specific folder exists you can use:
if exist(folder,'dir')
{do what you need}
end
sandy
2013년 9월 16일
thanks...i checked with your code..its not checking the existing files and not unzipping my files..any other idea?
Laurent
2013년 9월 16일
Difficult to say. Could you provide the exact code that you used and the exact location of these files? And did you get any errors?
this is the code i checked for my case,its not working
folder ='F:\test folder\';
for kk=2000:2013
if exist(folder,'dir')
for ll=1:12
if exist(folder,'dir')
for mm=1:31
currfold=[folder(mm) '\*.zip'];
currfiles=dir(currfold);
for jj=1:length(currfiles)
unzip([folder(ii) '\' currfiles(jj).name],outputfolder);
end
end
end
end
end
end
You are always using 'folder' and are not adding the year, month or date, when you check if they exist. I would change it in something like this:
Be aware that I did not check this code, so there could be small errors/mistakes, but I hope you get the idea.
for kk=2000:2013
yearfolder=[folder num2str(kk) '\'];
if exist(yearfolder,'dir')
for ll=1:12
monthfolder=[yearfolder num2str(ll) '\'];
if exist(monthfolder,'dir')
for mm=1:31
currfold=[monthfolder num2str(mm) '\'];
if exist(currfold,'dir')
currfiles=dir([currfold '*.zip']);
for jj=1:length(currfiles)
unzip([currfold '\' currfiles(jj).name],outputfolder);
end
end
end
end
end
end
end
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
참고 항목
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)
