dir or ls are not working properly

Hi,
I have a remote folder and there are many .mat files in it. I can see those files in windows explorer.
But in matlab command window, can cd into the folder by:
>cd rfolder
but dir or ls only show ". .." not those .mat files at all. I used to be able to ls or dir all the file names.
Why? Should I somehow add some path into matlab?
Thanks for any help.

12 Comments

Probably has something to do with permissions
You don't need to cd into a folder to list its content. In general, cd'ing into folders is a bad idea.
Can you give an example of the full path of a folder you cannot dir properly?
Are you sure you're actually in the folder you think you are? What does pwd returns?
@TADA, if listing the folder content works with the file explorer, it's unlikely to be a permission issue.
Thank you!
I do have permission to that folder.
Below is the code:
f = ''S:\A & B\CDE\FG\H\Spot\'
fname = '*.mat'
flist = dir(fullfile(f, fname))
It give only 3 items in the result flist
.
..
and a subfolder name.
'S:\A & B\CDE\FG\H\Spot\', that's not a path to a remote folder. That is a local path. If S: points to a remote location, how has this been set up? (using Map Network Drive in file explorer or using a third-party tool?)
Yes, S: is set up by Map Network Drive in file explorer.
Ok, so what does
system(sprintf('dir %s', fullfile(f, fname)));
display? The same 3 items, or a longer list?
Just tried the above on another folder which has one file and had the same problem before.
It is displaying the file I was looking for:
03/31/2019 10:00 AM 58,912,512 abc_20190401.mat
1 File(s) 58,912,512 bytes
0 Dir(s) 206,638,895,104 bytes free
So matlab can find the file. Then why isn't dir working?
Oh, wait, I just tried dir again and it is working! I am puzzled. Why didn't it work before?
You mentioned it is a remote folder. Often times changes made to remote folders after matlab has started wont' be recognized by matlab. The fix for this problem is to rehash path
rehash path
(though I'm not sure if this was your problem or not).
Thank you!
How to accept the answer here? I am not seeing the accept button.
I moved my comment to the answers section but only accept it if this solved your problem. There were lots of other great comments here that should be considered during troubleshooting.

Sign in to comment.

 Accepted Answer

Adam Danz
Adam Danz on 3 Apr 2019
Edited: Adam Danz on 3 Apr 2019
You mentioned it is a remote folder. Often times changes made to remote folders after matlab has started wont' be recognized by matlab. The fix for this problem is to rehash path
rehash path
For more info:

More Answers (0)

Categories

Products

Release

R2018b

Tags

Asked:

JFz
on 3 Apr 2019

Edited:

on 3 Apr 2019

Community Treasure Hunt

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

Start Hunting!