Clear HTML5 Filesystem API
-
31-05-2021 - |
Question
How does one completely empty (or delete all files in) a filesystem?
Is there no 1 line solution like localStorage (localStorage.clear()
)? Or am I missing something really, really obvious?
Apparently, I wasn't very clear. I'm referring to the HTML5 Filesystem API. http://www.html5rocks.com/en/tutorials/file/filesystem/
Solution
2016 Update: The File API "Directories and System" effort has been abandoned and what little support had made it into browsers is being dropped. The original File API is still valid, but the stuff providing an entire file area on the user's system has been abandoned.
It looks like DirectoryEntry#removeRecursively
does that. It says you can't remove the root of a file system, but you can loop through the entries in the root and remove them recursively (or just always work with a subdirectory of the root, thereby letting you remove that with a one-liner).
OTHER TIPS
Not a one line solution but you can always go to
chrome://settings/cookies
and remove the file system from the origin of your choice
In bro-fs there is special fs.clear() method exactly for that.
fs.init()
.then(() => fs.mkdir('dir'))
.then(() => fs.writeFile('file.txt', 'hello world'))
.then(() => fs.clear())
Storage, in the Web Storage specification, does have a clear
method. Are you confusing the File API with the web storage API?
At the level of the individual file, there's the truncate method.