For Programmers: Free Programming Magazines  


Home > Archive > Matlab > April 2005 > Find files with specific extension









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Find files with specific extension
LvdHulst

2005-04-21, 9:00 am

Hi,

I try to check if I have identical filesin a certain directory
including all the sub-directories.

I tried using this: [s, r] = dos('dir *.zip /s /b');

This works but this gives a result including the path names, making
it harder to check for identical file names.

In the Matlab "Find files" tool you have the opportunity to search
for files with a certain name/extension, but which routine is used
for this search?

Regards,
Lennard
Jérôme

2005-04-21, 9:00 am

Hi,

Search for "dir" in the File Exchange.
Some users contributions there.

<http://www.mathworks.com/matlabcent...loadCategory.do>

Jérôme
Lennard

2005-04-21, 4:03 pm

Solved it like this:

[sta, res] = dos('dir *.jpg /s /b');
% Note: You cannot run DOS commands when the path is a UNC
% (Universal Naming Convention) pathname, that is, starts with \\.
% Instead, use an actual hard drive on your system, or a mapped
network drive.

pnt_ind = strfind( res, '.');

fid1 = fopen( 'file_nms.txt', 'w');
fid2 = fopen( 'path_nms.txt', 'w');

for i = 1 : size( pnt_ind, 2)

if i==1
ind1 = 1;
ind2 = pnt_ind( 1);
else
ind1 = pnt_ind( i-1);
ind2 = pnt_ind( i);
end

tmp_ind = strfind( res( ind1 : ind2), '');

ind_min = ind1 -1 + min( tmp_ind);
ind_max = ind1 -1 + max( tmp_ind);

fprintf(fid1, '%s.jpg\n', res( 1+ind_max : -1+pnt_ind(i)));
fprintf(fid2, '%s\n', res( ind_min : ind_max));
end

fclose(fid1);
fclose(fid2);
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com