"Exist" return 0 for a file it displays when using "ls"

I'm using Matlab 2015a on window
I use "exist" to check the existence of a .stl file before opening it. This step was without any problem so far until last week. When checking the existence of files I had checked already in the past it return 0.
To make sure I used "ls", and runned "exist" on a copy paste of a file returned by "ls". But Matlab still denies the existence of the file
See below:
>> ls('M:\BM\Sebastian Ehrig\SJ\MeshSpheroids')
.
..
Movies
ellipsoid_x8_y8_z1_refSph6_sigma_0.417_Area452.389.stl
ellipsoid_x8_y8_z1_refSph6_sigma_0.417_Area452.389_Velocity_0.1.mat
old
meshes
structures >> exist('M:\BM\Sebastian Ehrig\SJ\MeshSpheroids\ellipsoid_x8_y8_z1_refSph6_sigma_0.417_Area452.389.stl')
ans =
0
>> exist('M:\BM\Sebastian Ehrig\SJ\MeshSpheroids\ellipsoid_x8_y8_z1_refSph6_sigma_0.417_Area452.389_Velocity_0.1.mat')
ans =
0
>> exist('M:\BM\Sebastian Ehrig\SJ\MeshSpheroids')
ans =
7

Answers (3)

The "." characters in the middle of your .mat file name probably cause exist to fail. This is generally a bad idea. A "." character is used to indicate an extension. So, the MATLAB exist tool looks for a file with the wrong name. It did not find a file with that name, even though ls sees a file in that directory.
The solution is more careful naming of your files.
On my system (MacOS 10.11) Matlab returns 2, as expected. I would try to get rid of the '.' in the file names and see if it works then. Of course if you do not have a pre-Windows-95 it should work with as many dots as you like, but still...
You might have non-printing graphics characters in the name.
dinfo = dir('M:\BM\Sebastian Ehrig\SJ\MeshSpheroids\*.stl');
fprintf('name looks like: "%s"\n', dinfo.name);
fprintf('which is length %d, and has representation\n', length(dinfo.name))
double(dinfo.name)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Asked:

on 22 Jun 2016

Answered:

on 22 Jun 2016

Community Treasure Hunt

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

Start Hunting!