"Exist" return 0 for a file it displays when using "ls"
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(3 个)
John D'Errico
2016-6-22
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.
0 个评论
Thorsten
2016-6-22
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...
0 个评论
Walter Roberson
2016-6-22
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!