6
$\begingroup$

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"]

Uncompress@Import["./test.mc"]

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

FileNames["./test.mc"]

>>> {} 

Now importing again works without error:

Uncompress@Import["./test.mc"]

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

Now deleting the file within Mathematica:

DeleteFile["./test.mc"]

Uncompress@Import["./test.mc"]

>>> Import::nffil: File not found during Import. >>
Uncompress::string: String expected at position 1 in Uncompress[$Failed]. >>
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.

$\endgroup$
7
  • $\begingroup$ Does checking with FileExistsQ instead of Import work? $\endgroup$ Mar 25, 2015 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$ Mar 25, 2015 at 17:03
  • $\begingroup$ Let me guess, you're on OSX? $\endgroup$ Mar 25, 2015 at 17:06
  • $\begingroup$ No, I'm on Linux Debian 3.2.65. $\endgroup$
    – Santiago
    Mar 25, 2015 at 17:08
  • $\begingroup$ Yes, @2012rcampion, changing the check would be enough. I just find this a very strange behavior. $\endgroup$
    – Santiago
    Mar 25, 2015 at 17:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.