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:
files in a folder

Subject: files in a folder

From: Jessica

Date: 19 Jun, 2010 03:54:04

Message: 1 of 4

I am trying to get a list of all the .xls files in a folder by using the dir command (I want to get it so that each file can then be called up separately):

FileNames=dir('/Volumes/Drive12/'')
FileNames(1).name
FileNames(2).name
FileNames(3).name
.
.
.


However, when I try to just get the .xls files, it doesn't work:

FileNames=dir('/Volumes/Drive12/','*.xls').

Any suggestions for what is wrong with my code?

Thanks!

Subject: files in a folder

From: Walter Roberson

Date: 19 Jun, 2010 04:00:02

Message: 2 of 4

Jessica wrote:

> However, when I try to just get the .xls files, it doesn't work:
>
> FileNames=dir('/Volumes/Drive12/','*.xls').
>
> Any suggestions for what is wrong with my code?

You failed to mention the error you get,

??? Error using ==> dir
Too many input arguments.

That was a clue that you should examine the documentation of dir() and
notice that it can only take a single argument. Try

dir('/Volumes/Drive12/*.xls')

Subject: files in a folder

From: ImageAnalyst

Date: 19 Jun, 2010 04:01:44

Message: 3 of 4

With my version of MATLAB, dir() does not take two arguments. Try

FileNames = dir('/Volumes/Drive12/*.xls');

or

FileNames = dir(fullfile('/Volumes/Drive12/', '*.xls'));
which is similar to the example the help shows,
and which is the same as
FilePattern = fullfile('/Volumes/Drive12/', '*.xls');
FileNames = dir(FilePattern);

Subject: files in a folder

From: us

Date: 19 Jun, 2010 04:04:22

Message: 4 of 4

"Jessica" <jyorzinski@ucdavis.edu> wrote in message <hvhf0s$50$1@fred.mathworks.com>...
> I am trying to get a list of all the .xls files in a folder by using the dir command (I want to get it so that each file can then be called up separately):
>
> FileNames=dir('/Volumes/Drive12/'')
> FileNames(1).name
> FileNames(2).name
> FileNames(3).name
> .
> .
> .
>
>
> However, when I try to just get the .xls files, it doesn't work:
>
> FileNames=dir('/Volumes/Drive12/','*.xls').
>
> Any suggestions for what is wrong with my code?
>
> Thanks!

well, yes...
what about using the correct syntax, eg,

one of the solutions

     fn=dir('/Volumes/Drive12/*.xls')

us

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