필터 지우기
필터 지우기

how to access zip files in the directory?

조회 수: 16 (최근 30일)
sandy
sandy 2013년 9월 5일
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
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
sandy 2013년 9월 16일
편집: sandy 2013년 9월 16일
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
Laurent
Laurent 2013년 9월 16일
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개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by