FileSystem

檔案與目錄 API 的 FileSystem 介面用來表示檔案系統。這些物件可從任何檔案系統項目上的 filesystem 屬性取得。某些網頁瀏覽器提供額外的 API 去建立和管理檔案系統,例如 Google Chrome 的 requestFileSystem() 方法。

此介面並不會讓你直接存取使用者電腦的檔案系統,而是在瀏覽器的沙盒內建立一個「虛擬磁碟」讓你操作。如果要直接操作使用者的檔案系統,需要向使用者請求,像是安裝 Google Chrome 擴充功能之類的。相關的 Chrome API 可在此找到。

基礎概念

存取 FileSystem 物件的兩種方法:

  1. 你可以呼叫 window.requestFileSystem(),為你的網頁應用程式建立一個檔案系統的沙盒。如果呼叫成功,將會執行回呼函式,該回呼函式會有個 FileSystem 參數來描述檔案系統。
  2. 從檔案系統項目物件的 filesystem 屬性中取得。

實例屬性

FileSystem.name Read only

代表檔案系統名稱的字串。此名稱在整個檔案的清單中是唯一的。

FileSystem.root Read only

為一個 FileSystemDirectoryEntry 物件,用來表示檔案系統的根目錄。透過此物件,你可以取得檔案系統中的所有的檔案與目錄。

規範

Specification
File and Directory Entries API
# api-domfilesystem

瀏覽器相容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
FileSystem
name
root

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

參見