Aaron A.
Aaron A.

Reputation: 33

MATLAB doesn't find files I downloaded while the script is running

My problem is as described. My script downloads files through an external call to cmd (using the system function and then .NET to make keypresses). The issue is that when it tries to fopen these files I downloaded (filenames from a text file I write as I download), it doesn't find them, causing an error. When I run the script again after seeing it fail, it works but only up to the point where it's trying to download/call new files again, where it runs into the same problem.

Are new files downloaded during when a script is running somehow not visible to the search path? Because the folder is most definitely in my search path (seeing as it works outside of during-script downloads). It's not that it isn't getting the files fast enough either, cause they appear in my folder almost instantly, and I've tried a delay to allow for it to recognize it, but that didn't work either.

I'm not sure if it's important to note that the script calls an external function which tries to read the files from the .txt list I create in the main script.

Any ideas?

The script to download the files looks like so:

NET.addAssembly('System.Windows.Forms'); sendkey = @(strkey) System.Windows.Forms.SendKeys.SendWait(strkey); system('start cygwinbatch.bat') pause(.1) sendkey(callStr1) sendkey('{ENTER}') pause(.1) sendkey(callStr2) sendkey('{ENTER}') pause(.1) sendkey('exit') pause(2) sendkey('{ENTER}')

But that is not the main reason I am asking: I am confident that the downloads are occurring when the script calls them, because I see them appearing in my folder as it called. I am more confused as to why MATLAB doesn't seem to know they are there while the script is running, and I have to stop it and run it again for it to recognize the ones I've downloaded already.

Thank you,

Aaron

Upvotes: 1

Views: 129

Answers (2)

Pursuit
Pursuit

Reputation: 12345

The answer here is probably to run the 'rehash' function. Matlab does not look for new files while executing an operation, and in some environments misses new files even during interactive activity.

Running the rehash function forces Matlab to search through its full path and determine if there are any new files.

I've never tried to run rehash in the middle of an operation though. ...

Upvotes: 2

surgical_tubing
surgical_tubing

Reputation: 148

My guess is that the MATLAB interpreter is trying to look ahead and is throwing errors based on a snapshot of what the filesystem looked like before the files were downloaded. Do you get different behavior if you run it one line at a time using F9? If that's the case then you may be able to prevent the interpreter from looking ahead by using eval().

Upvotes: 0

Related Questions