Apparently Import keeps an imported file in the cache and doesn't complain for some time if a file is deleted manually from the system and then it is imported. If the file is deleted from within Mathematica, then it does complain. Here is a minimal working example:

list = {{1, 2, 3, 4}, {4, 5, 6}};

Export["test.mc", Compress@list, "String"]


This is successful. Now delete the file manually from your Directory and check that it is indeed deleted:


>>> {} 

Now importing again works without error:


>>> {{1, 2, 3, 4}, {4, 5, 6}}

Now deleting the file within Mathematica:



>>> Import::nffil: File not found during Import. >>
Uncompress::string: String expected at position 1 in Uncompress[$Failed]. >>

Can someone explain what is going on here?

Apparently clearing the SystemCache and waiting some time, works.

This is important for me because I have a function that detects if a file has been deleted using Check[Import[....]]. This means that my function doesn't work if the file is recently deleted in my system.

I am using Mathematica 9.0.1 in Debian Linux 3.2.65.

  • $\begingroup$ Does checking with FileExistsQ instead of Import work? $\endgroup$ – 2012rcampion Mar 25 '15 at 17:01
  • $\begingroup$ Also, can't reproduce behavior (MMA 10.0.0, Windows 8.1 64-bit), I just get Import::nffil immediately. $\endgroup$ – 2012rcampion Mar 25 '15 at 17:03
  • $\begingroup$ Let me guess, you're on OSX? $\endgroup$ – 2012rcampion Mar 25 '15 at 17:06
  • $\begingroup$ No, I'm on Linux Debian 3.2.65. $\endgroup$ – Santi Mar 25 '15 at 17:08
  • $\begingroup$ Yes, @2012rcampion, changing the check would be enough. I just find this a very strange behavior. $\endgroup$ – Santi Mar 25 '15 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.