Clear HTML5 Filesystem API
Asked Answered
C

4

7

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/

Chlordane answered 14/4, 2012 at 22:4 Comment(3)
I am asking if there's a simple way to clear the Filesystem API like you can with localStorage.Chlordane
Come on, this question is pretty clear.Scranton
@minitech: With the edit, it is.Absurd
A
7

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).

Absurd answered 14/4, 2012 at 22:22 Comment(5)
@J.Chase: Good deal, glad that helped.Absurd
Am I missing something or is that link no longer providing info on that? I found relevant info on removeRecursively here: html5rocks.com/en/tutorials/file/filesystemTayler
@MrColes: It wasn't just you. That effort has been abandoned and they updated the main spec link to just be a statement of abandonment. I've linked to the dev spec, but you shouldn't use this stuff, it was never broadly supported and what support exists in browsers is likely being dropped.Absurd
Ahh, bummer. I have a chrome extension called Full Page Screen Capture that uses this API to save the files. Cleaning up files is a problem I need to solve, but this might be a bigger problem at some point!Tayler
@MrColes: Ah, apologies, if you're in a Chrome extension I don't know that you have to worry. They certainly don't talk about removing the file system API for apps (link), so it may be they'll leave it in place for things like extensions. I was talking about using it on web pages, I should have been more clear.Absurd
I
2

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 enter image description here

Intermingle answered 19/1, 2015 at 0:58 Comment(1)
This method worked best for me. I had a huge file (3.1GB) from Mega Upload and this was the only method that I could find to remove it.Cheremkhovo
L
0

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())
Lacielacing answered 24/10, 2016 at 19:54 Comment(0)
D
-1

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.

Deena answered 14/4, 2012 at 22:15 Comment(2)
I don't think so. I'm referring to this: html5rocks.com/en/tutorials/file/filesystemChlordane
I referred to the exact name of the API in the original title. I will keep in mind for the future to be redundantly specific. Again, sorry.Chlordane

© 2022 - 2024 — McMap. All rights reserved.