Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
dir('*.mat') returns *.mat*

Subject: dir('*.mat') returns *.mat*

From: BrianS

Date: 7 Jun, 2005 07:42:14

Message: 1 of 9

Is this a know issue?

dir('*.mat') returns *.mat*

I searched the groups and the support site and found no mention of it.

Thanks,

Brian

Subject: dir('*.mat') returns *.mat*

From: Dan Hensley

Date: 7 Jun, 2005 09:36:10

Message: 2 of 9

On Tue, 07 Jun 2005 07:42:14 -0700, BrianS wrote:

> Is this a know issue?
>
> dir('*.mat') returns *.mat*
>
> I searched the groups and the support site and found no mention of it.

Welcome to the world of Windows. This is an OS issue, not a Matlab issue.
 I've complained about it before, but there's not much they can do.
 You'll have to write code to work around this.

Dan



>
> Thanks,
>
> Brian

Subject: dir('*.mat') returns *.mat*

From: us

Date: 7 Jun, 2005 12:43:53

Message: 3 of 9

BrianS:
<SNIP former OS related problem...

> dir('*.mat') returns *.mat*

what release do you have?
r14.sp2 returns this on a typical wintel

     dir('*.mat')
% *.mat not found.

us

Subject: dir('*.mat') returns *.mat*

From: TigerJade

Date: 7 Jun, 2005 12:31:23

Message: 4 of 9

I don't have this problem with Matlab 6.51 and win2k sp4.
Maybe it's OS or version specific?

Subject: dir('*.mat') returns *.mat*

From: Steve Amphlett

Date: 7 Jun, 2005 16:48:16

Message: 5 of 9

<snip, globbing problem...

I'm not sure of the answer, but the question is clearly a globbing
issue. Putting the trivial OS of Windows to one side, most shells
glob by default. command *.xxx expands the *.xxx before execution to
a command with many arguments. However, command "*.xxx" treats the *
as an asterisk. I reckon ML's dir() function execs a single command
with a single argument (not using the shell's globbing). Bear in
mind that the folowing are all valid filenames (although some are
really hard to work with and ML may not like them):

ab.mat
a b.mat
a\b.mat
a/b.mat
a\/b.mat
a*b.mat
a"b.mat
a'"b.mat
\a\b.mat

Subject: dir('*.mat') returns *.mat*

From: Kelly

Date: 7 Jun, 2005 17:09:02

Message: 6 of 9

Steve Amphlett wrote:

> I'm not sure of the answer, but the question is clearly a globbing
> issue. Putting the trivial OS of Windows to one side, most shells
> glob by default. command *.xxx expands the *.xxx before execution
> to
> a command with many arguments. However, command "*.xxx" treats the
> *
> as an asterisk. I reckon ML's dir() function execs a single
> command
> with a single argument (not using the shell's globbing).

Steve, could you clarify a bit more for the computer-near-illiterate
like me? Were you saying that Matlab's dir function doesn't accept *
as a wildcard? Because that's certainly not the case. I just ran a
quick test, and this behavior seems to be limited specifically to the
.mat extension. I'm running Matlab 7.0.4 on Windows 2000, and I'm
seeing the following behavior:

>> dir('test*')

test.m test.mat test.matstuff

>> dir('test*.m')

test.m

>> dir('test*.ma')
test*.ma not found.
>> dir('test*.mat')

test.mat test.matstuff

Is this still a Windows issue? If so, can someone explain what is so
special about this particular extension?

-Kelly

Subject: dir('*.mat') returns *.mat*

From: Tom Lane

Date: 7 Jun, 2005 17:40:18

Message: 7 of 9

"Kelly" <kakearney@NOSPAMcomcast.net> wrote in message >>> dir('test*.mat')
>
> test.mat test.matstuff
>
> Is this still a Windows issue? If so, can someone explain what is so
> special about this particular extension?

Kelly, I believe the special thing is that it has three letters. The DOS
8.3 name has the same suffix in both cases. This is all from the DOS
prompt, not from MATLAB:

D:\Work\temp>dir *.mat

06/07/2005 05:37 PM 0 temp.mat
06/07/2005 05:37 PM 0 temp.matstuff

D:\Work\temp>dir /x *.mat

06/07/2005 05:37 PM 0 temp.mat
06/07/2005 05:37 PM 0 TEMP~1.MAT temp.matstuff


-- Tom

Subject: dir('*.mat') returns *.mat*

From: Steve Amphlett

Date: 8 Jun, 2005 04:03:31

Message: 8 of 9

Kelly wrote:
>
<snip, ramblings about globbing...
>
> Steve, could you clarify a bit more for the
> computer-near-illiterate
> like me? Were you saying that Matlab's dir function doesn't accept
> *
> as a wildcard? Because that's certainly not the case.

Sorry, I was posting from home and couldn't test. Just to clarify
what I meant by globbing though (if it's of any interest): When
programs start (in most OSs) the command string contains the program
name followed by a load of arguments. Most programs will not assume
that * is meant as a wildcard - this is normally the job of the shell
or command line interpreter. It will do the wildcard expansion for
you and pass the newly created argument list in full to the program.
To pass a * to a program (at lease in UNIX shells), you either need
to disable globbing or quote the *. E.g. in a UNIX shell, touch
"*.mat" will create a file called *.mat

Subject: dir('*.mat') returns *.mat*

From: Sami

Date: 13 Dec, 2013 02:17:06

Message: 9 of 9

All, here is what I did for it,

Syntax:
MatFiles = DirMat();

You can also change the '*.mat' to any extension you need.

-------------------------------
function [listFound] = DirMat();
list = dir([DirLoc '*.*']);
listFound = {};
i = 0;
if ~isempty(list)
     while i < size(list,1)
            i = i+1;
             [pathstr, name, ext] = fileparts(list(i).name);
            if (strcmp(ext, '.mat'))
                if isempty(listFound),
                    listFound = mat2cell(name);
                else
                    listFound(end+1,1) = mat2cell(name);
                end
                
            end
            
        end

else % Empty
    
    disp ' Empty Directory';
    
end
end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us