Clear Filters
Clear Filters

How to access a file in another directory

9 views (last 30 days)
Hi there!
I'm writting a script located in the driver 'E:\' and I want it to access a file in 'C:\'.
When try to read the file I receive this message:
>> ls C:\Program Files\MATLAB\R2018a\toolbox
Error using ls (line 60)
Too many input arguments.
I've also tried using '/' before 'Files' and received the same error message:
>> ls C:\Program/ Files\MATLAB\R2018a\toolbox
Error using ls (line 60)
Too many input arguments.
Why is it happening and how can I overcome this problem?
Thanks in advance!
  1 Comment
Stephen23
Stephen23 on 30 Apr 2020
"C:\Program Files\MATLAB\R2018a\toolbox"
Accessing files directly inside any application's installation folder is a very dubious idea. Most likely you should just set the MATLAB Search Path and rely on MATLAB to locate the files.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 30 Apr 2020
Edited: Stephen23 on 30 Apr 2020
The problem is that you are using command syntax (an unfortunate remnant of MATLAB's venerable origins):
With command syntax every space separates one variable. Look at your code and find the spaces:
ls C:\Program Files\MATLAB\R2018a\toolbox
% ^ ^ two spaces!
So if we were to write your command syntax as a normal function call, it would look like this:
ls('C:\Program','Files\MATLAB\R2018a\toolbox')
% ^^^^^^^^^^^^ 1st input
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2nd input
So how many inputs are you calling ls with? (hint: two)
The best solution is to forget about (awful, outdated, ugly) command syntax and always use function syntax:
ls('C:\Program Files\MATLAB\R2018a\toolbox')

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!