A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory below:

HTMLInputElement: webkitdirectory property - Web APIs

HTMLInputElement: webkitdirectory property

The webkitdirectory property of the HTMLInputElement interface reflects the webkitdirectory HTML attribute, which indicates that <input type="file"> elements should let the user select directories instead of files.

When a directory is selected, the directory and its entire hierarchy of contents are included in the set of selected items. The selected file system entries can be obtained using the webkitEntries property.

Note: This property is called webkitdirectory in the specification due to its origins as a Google Chrome-specific API. It's likely to be renamed someday.

Value

A Boolean; true if the <input> element should allow picking only directories or false if only files should be selectable.

Description

Setting webkitdirectory true causes the input to offer users directories to select instead of files.

After the user makes a selection, each File object in files has its File.webkitRelativePath property set to the relative path within the selected directory at which the file is located.

For example, consider this file system:

If the user chooses PhotoAlbums, then the list reported by files will contain File objects for every file listed above—but not the directories. The entry for PIC2343.jpg will have a webkitRelativePath of PhotoAlbums/Birthdays/Don's 40th birthday/PIC2343.jpg. This makes it possible to know the hierarchy even though the FileList is flat.

Note: The behavior of webkitRelativePath is different in Chromium < 72. See this bug for further details.

Examples

In this example, a directory picker is presented which lets the user choose one or more directories. When the change event occurs, a list of all files contained within the selected directory hierarchies is generated and displayed.

HTML
<input type="file" id="file-picker" name="fileList" webkitdirectory multiple />
<ul id="listing"></ul>
JavaScript
document.getElementById("file-picker").addEventListener(
  "change",
  (event) => {
    let output = document.getElementById("listing");
    for (const file of event.target.files) {
      let item = document.createElement("li");
      item.textContent = file.webkitRelativePath;
      output.appendChild(item);
    }
  },
  false,
);
Result Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4