File: webkitRelativePath property

Baseline 2025
Newly available

Since August 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

Thuộc tính chỉ đọc webkitRelativePath của giao diện File chứa một chuỗi xác định đường dẫn của tệp tương đối với thư mục được người dùng chọn trong phần tử <input> có thuộc tính webkitdirectory được đặt.

Giá trị

Một chuỗi chứa đường dẫn của tệp tương đối với thư mục gốc mà người dùng đã chọn.

Ví dụ

Trong ví dụ này, một bộ chọn thư mục được hiển thị cho phép người dùng chọn một hoặc nhiều thư mục. Khi sự kiện change xảy ra, danh sách tất cả các tệp trong cấu trúc thư mục đã chọn được tạo và hiển thị.

HTML

html
<input type="file" id="file-picker" name="fileList" webkitdirectory multiple />
<output id="output"></output>

JavaScript

js
const output = document.getElementById("output");
const filePicker = document.getElementById("file-picker");

filePicker.addEventListener("change", (event) => {
  const files = event.target.files;

  for (const file of files) {
    output.textContent += `${file.webkitRelativePath}\n`;
  }
});

Kết quả

Thông số kỹ thuật

Thông số kỹ thuật
File and Directory Entries API
# dom-file-webkitrelativepath

Tương thích trình duyệt

Xem thêm