Search code examples
matlabfile-iopathfile-exists

In MATLAB exist( x, 'file' ) takes forever


I am using exist(x, 'file') to check for the existence of a file on my machine. The execution of this command takes FOREVER (over 10 seconds per call!).

My matlabpath is not too long (about 200 entries) and all folders on path are on my local drive (no network).

  1. Why does exist takes forever?
  2. Is there a way to make it run FASTER?

PS,
This call to exist is part of Matlab's execution of loadlibrary. So, if you are calling loadlibrary and you don't know why it takes forever - this question is also for you.


Solution

  • Wow! That was a tough one. Bottom line: Delete %TEMP% files!

    I had a few thousands files lying around in %TEMP%. It appears MATLAB really likes to go over and over the TEMP directory.

    After clearing the TEMP folder, exist runs in no time!

    (Thanks Andrew for the Process Monitor advice!)