Roman
Roman

Reputation: 131168

Why matlab does not understand * in the names of files?

I tried to use:

dir('dirname\*')

and it did not work. It started to work after I started to use:

dir('dirname\m*')

Does anybody know why?

Upvotes: 3

Views: 8223

Answers (3)

rubenvb
rubenvb

Reputation: 76579

Matlab does understand wildcards *, but in the way you unluckiliy tried to adhere to Windows cmd path conventions, you entered the string \*, which is a literal asterisk (due to the escaping backslash).

A workaround, or the preferred way to specify paths on all platforms, is using a forward slash / as a directory seperator.

dir('dirname/*')

This also explains why adding the m after the backslash "fixed" the issue; the asterisk was no longer a literal asterisk, but allowed to be interpreted as a wildcard character.

EDIT: Documentation explicitely says the wildcard character is allowed and works as expected (see my explanation above).

Upvotes: 7

Clement J.
Clement J.

Reputation: 3032

What is your OS ? Here on Windows, the first line works well. However, the "*" is maybe considered by Matlab as a literal "*". What happens with dir('dirname/*') ?

Upvotes: 0

Dawn
Dawn

Reputation: 3628

Try to provide the full path, like dir('c:\dirname*.m'), and make sure the folder 'dirname' exists.

Upvotes: 0

Related Questions