how to fetch files from each sub directory?

2 visualizzazioni (ultimi 30 giorni)
sandy
sandy il 16 Set 2013
hi ..example.if i have a folder name as 'DATA',inside this subfolder namely 2000 to 2013(year) are ther..in this each folder(01 TO 12,say month),in each month folder,o1 to 31 days folder are ther,inside each days folder 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? i couldnt do with below code..help need
for kk=1997:2013
if exist(folder,'dir')
for ll=1:12
if exist(folder,'dir')
for mm=1:31
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
end
end
end
end

Risposte (1)

David Sanchez
David Sanchez il 16 Set 2013
Use the dir2 function. With it, you can fetch files recursively.
  1 Commento
sandy
sandy il 16 Set 2013
Modificato: sandy il 17 Set 2013
thanks,if i use dir2() function...it showing error as......
lcc preprocessor error: dir2_mex.c:4 Could not find include file <shlwapi.h>
Warning dir2_mex.c: 89 assignment of pointer to pointer to char to pointer to char
Warning dir2_mex.c: 90 assignment of pointer to pointer to char to pointer to char
Warning dir2_mex.c: 91 assignment of pointer to pointer to char to pointer to char
Warning dir2_mex.c: 92 assignment of pointer to pointer to char to pointer to char
Warning dir2_mex.c: 93 assignment of pointer to pointer to char to pointer to char
Error dir2_mex.c: 104 operands of != have illegal types `int' and `pointer to void'
Error dir2_mex.c: 104 too many arguments to `fileSplit'
Error dir2_mex.c: 104 too many arguments to `fileSplit'
Warning dir2_mex.c: 104 possible usage of fn before definition
Warning dir2_mex.c: 104 possible usage of dir before definition
Warning dir2_mex.c: 104 possible usage of parts before definition
Warning dir2_mex.c: 104 assignment of pointer to pointer to char to pointer to char
Warning dir2_mex.c: 104 assignment of pointer to pointer to char to pointer to char
Error dir2_mex.c: 104 operands of != have illegal types `int' and `pointer to void'
Warning dir2_mex.c: 104 assignment of pointer to pointer to char to pointer to char
Error dir2_mex.c: 107 operands of != have illegal types `int' and `pointer to void'
Error dir2_mex.c: 107 too many arguments to `fileSplit'
Error dir2_mex.c: 107 too many arguments to `fileSplit'
Warning dir2_mex.c: 107 assignment of pointer to pointer to char to pointer to char
Warning dir2_mex.c: 107 assignment of pointer to pointer to char to pointer to char
Error dir2_mex.c: 107 operands of != have illegal types `int' and `pointer to void'
Warning dir2_mex.c: 107 assignment of pointer to pointer to char to pointer to char
Warning dir2_mex.c: 121 assignment of pointer to pointer to char to pointer to char
Error dir2_mex.c: 127 operands of = have illegal types `pointer to char' and `int'
Warning dir2_mex.c: 131 assignment of pointer to pointer to const char to pointer to pointer to pointer to char
Warning dir2_mex.c: 135 assignment of pointer to pointer to char to pointer to pointer to pointer to char
Warning dir2_mex.c: 137 assignment of pointer to pointer to char to pointer to pointer to pointer to char
Error dir2_mex.c: 150 extraneous return value
Warning dir2_mex.c: 80 local `int hasRec' is not referenced
Error dir2_mex.c: 255 undeclared identifier `MAXDWORD'
Warning dir2_mex.c: 269 assignment of pointer to char to pointer to pointer to char
Warning dir2_mex.c: 270 assignment of pointer to const char to pointer to pointer to char
Warning dir2_mex.c: 255 possible usage of MAXDWORD before definition
Warning dir2_mex.c: 324 assignment of pointer to const char to pointer to array 261 of char
Error dir2_mex.c: 357 operands of = have illegal types `pointer to char' and `int'
Error dir2_mex.c: 358 operands of = have illegal types `char' and `pointer to void'
Error dir2_mex.c: 359 operands of = have illegal types `pointer to char' and `int'
Error dir2_mex.c: 360 operands of = have illegal types `char' and `pointer to void'
Warning dir2_mex.c: 345 local `pointer to char temp' is not referenced
16 errors, 24 warnings
C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: Compile of 'dir2_mex.c' failed.
??? Undefined function or method 'printf' for input arguments of type 'char'.
Error in ==> dir2>install_dir2_mex at 202 printf('COuld not install the mex file. Switch to the .m version\n');
Error in ==> dir2 at 50 install_dir2_mex;
Error in ==> append at 2 d = dir2(folder,'*.zip');

Accedi per commentare.

Categorie

Scopri di più su Scope Variables and Generate Names in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by