This works for me. It's based on the fact that addr is zero when a file does not exist. When a file exists addr is not zero but points to an address in Storage.
var Storage = require("Storage");
l=Storage.list();
print(l);
function exists(name){
return Boolean(Storage.open(name,"r").addr);
}
print(exists("news.txt"));
print(exists("nonews.txt"));
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
This works for me. It's based on the fact that
addr
is zero when a file does not exist. When a file existsaddr
is not zero but points to an address in Storage.The output is:
[
"news.txt\1",
"weath0.txt\1",
"weath1.txt\1",
"stocks.txt\1",
"messages.txt\1"
]
true
false