0

I started learning matlab very recently and am stuck on this issue.

My code looks like this:

fileloc = '/no_backup/GroupData/ESRL/Download_18Mar2014/surface/'
list = dir(fileloc, '*.txt') 
numTextFiles = length(list) 
disp(numTextFiles)

So far I am just checking to see if it has read in the correct amount of text files, but it gives me the error:

"Error using dir
Too many input arguments."

I tried replacing

list = dir(fileloc, '*.txt') 

to

list = dir(strcat(fileloc, '*.txt')) 

(just in case my syntax was completely wrong since I have no idea)

but then it prints

numTextFiles =
       0
       0

I am just wondering if any of the functions I'm using are inappropriate and if so, which ones would I use/how would I use those and how would I just display the number of text files I have in that folder?

admdrew
  • 3,790
  • 4
  • 27
  • 39
user3613290
  • 461
  • 6
  • 18
  • Have a look at this solution https://stackoverflow.com/questions/2652630/how-to-get-all-files-under-a-specific-directory-in-matlab – Raab70 May 07 '14 at 19:33

1 Answers1

0

the argument to dir should be directoryname/*.txt or directoryname\*.txt if you're on windows. you can achieve this with

list = dir([ fileloc filesep '*.txt' ]);

[] concatenates strings. filesep is a builtin that evaluates to a string of the separator for your OS.

honi
  • 946
  • 1
  • 7
  • 18
  • i'm actually on unix..this doesn't work :( same output for numTextFiles = 0 0 – user3613290 May 07 '14 at 20:27
  • it works on my machine. is the code you have here the exact code you are running? print `list`. what does it say? – honi May 07 '14 at 20:58
  • When I use your suggestion (list = dir([fileloc filesep '*.txt']); it says: list = 0x1 struct array with fields: name date bytes isdir datenum numTextFiles = 0 0 – user3613290 May 08 '14 at 16:22
  • are you sure there are .txt files in that location? are you sure fileloc is correct? – honi May 08 '14 at 16:54