from
Get files of any extention to a folder
by Shanmugam Kannappan
Get files from folder containing many subfolders & files in each subfolder
|
| GetFlsFrmFolder
|
function GetFlsFrmFolder
% This is function gets all the files of your choice from number of
% subfolders to the current directory in MATLAB
% If you don't like to have extension dialog comment line number 19 & enter
% ext = 'mdl' or 'xls' etc
MainDir = uigetdir(' ','Select the main Folder to Extract files'); % Select the main directory(folder)
if MainDir ~=0 % if folder is selected
FldrPath=genpath(MainDir); % Get the path of all the folder & Subfolders
i=1;
while true
[SubFldr, FldrPath] = strtok(FldrPath, ';');
if isempty(SubFldr) % if all the paths are extracted
break; % exit from here
elseif ~isempty(regexp(SubFldr,'.svn','match')) % If the directory is SVN temporary directory then skip it
continue
end
FldrName{i}=SubFldr; % Get only the valid folders
i=i+1;
end
ext = cell2mat(inputdlg('Extensions','Type of files to extract',1,{'mdl'})); % Get the file extension to extract from the folders
for j=1:length(FldrName) % Get all the files from each subfolder
Mdl=dir([FldrName{j} '\*.' ext]); % Get all the files from each
if ~isempty(Mdl) % If there is no such files in that directory skip it
for l=1:length(Mdl)
copyfile([FldrName{j} '\' Mdl(l).name] ,eval('pwd')) % Copy the files one by one
end
end
end
end
|
|
Contact us at files@mathworks.com