MATLAB: EXIST ignores leading slash

existpath

The EXIST function is reporting that a file exists when it does not. I'm trying to test the existence of the file '/license/license.json', which does not exist on my file system. The file 'license.json' is in my path, but the directory '/license' does not exist on my system.
>> exist('/license', 'dir')
ans =
0
>> exist('/license/license.json', 'file')
ans =
2
>> which('/license/license.json')
/Users/brian/apps/copilot/license/license.json
>> which('license.json')
/Users/brian/apps/copilot/license/license.json
Am I misunderstanding the use of EXIST? Why is it ignoring the leading slash in an absolute path?
UPDATE: a workaround to check the existence of a file given its absolute path is provided by OCDER below:
FileLoc = dir('/license/license.json')
IsFileThere = ~isempty(FileLoc) && any(~[FileLoc.isdir]);

Best Answer

NEWER ANSWER
FileLoc = dir('/license/license.json')
IsFileThere = ~isempty(FileLoc) && any(~[FileLoc.isdir]);
NEW ANSWER
exist behaves differently when searching for a file vs a dir. For a file search, it will search for file name in the matlab path, a partial match from the right hand side are valid. SO
exist('/license/license.json', 'file') %Works because it's searching:
1) matlabpath/**/license/license.json (if fail, look at root)
2) root/license/license.json
When looking for a directory, the leading slash is immediately treated as the root directory. It doesn't seem to be looking for a partial match, unless the leading slash is removed.
exist('/license', 'dir') %Looks immediately for root/license
exist('license', 'dir') %Looks at matlab path, but NOT root or elsewhere
OLD ANSWER
The first '/' is treated as the hard drive ("C:\") for Windows 10 at least.
exist('/Users', 'dir') should work
exist('/Users/brian/apps/copilot/license', 'dir') should work
exist('/license', 'dir') should not work, because your license folder is NOT
at '/license' but '/Users/brian/apps/copilot/license'
exist('license', 'dir) should work, because you are now looking for CURRENT_FOLDER/license, where
CURRENT_FOLDER = '/Users/brian/apps/copilot'