Reputation: 790
I am using dir
function to list the content of a folder but it gives .
and ..
for first two folder. Is there any way to get rod of this silly process.
Can I use regular expression in dir
function ? (if I can, it can be a solution)
Upvotes: 3
Views: 6157
Reputation: 20915
I don't know of any built-in solution, but I tend to do the following:
d = dir ('C:\');
d(~[d.isdir])= []; %Remove all non directories.
names = setdiff({d.name},{'.','..'});
The setdiff
command removes the unwanted elements.
Another cheap way to get rid of .
and ..
is using wildcards (Windows only):
d = dir ('C:\*.*');
Upvotes: 6
Reputation: 13088
How about this
list = dir('/var/temp');
list = list(3:end,:);
that's of course assuming that the first two entries indeed are .
and ..
which might not be the case on all OSes
Upvotes: 4
Reputation: 21351
By the sound of this documentation, dir
simply displays what gets returned by the operating system itself so I doubt you will be able to suppress it without doing some post processing of the list that gets returned
http://www.mathworks.co.uk/help/techdoc/ref/dir.html
dir does support the wildcard character *
Upvotes: 2