How to access a file in another directory
16 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2020-4-30
"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.
采纳的回答
Stephen23
2020-4-30
编辑:Stephen23
2020-4-30
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')
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!