# Import successful when file manually deleted

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

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.

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