Nhận tên tệp từ đường dẫn JavaScript

Trả về tên của tệp được đại diện bởi một đối tượng

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
3. Vì lý do bảo mật, đường dẫn bị loại trừ khỏi thuộc tính này

Show

Một chuỗi, chứa tên của tệp không có đường dẫn, chẳng hạn như "My Resume. rtf"

<input type="file" id="filepicker" multiple />
<div>
  <p>List of selected files:</p>
  <ul id="output"></ul>
</div>

const output = document.getElementById('output');
const filepicker = document.getElementById('filepicker');

filepicker.addEventListener('change', (event) => {
  const files = event.target.files;
  output.textContent = '';

  for (const file of files) {
    const li = document.createElement('li');
    li.textContent = file.name;
    output.appendChild(li);
  }
})

Sự chỉ rõ

Bảng BCD chỉ tải trong trình duyệt có bật JavaScript. Bật JavaScript để xem dữ liệu

  • Sử dụng tệp từ ứng dụng web

Tìm thấy một vấn đề với trang này?

  • Chỉnh sửa trên GitHub
  • Nguồn trên GitHub
  • Báo cáo sự cố với nội dung này trên GitHub
  • Bạn muốn tự khắc phục sự cố?

Sửa đổi lần cuối. Ngày 14 tháng 9 năm 2022, bởi những người đóng góp MDN

Mô-đun

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
4 cung cấp các tiện ích để làm việc với đường dẫn tệp và thư mục. Nó có thể được truy cập bằng cách sử dụng

const path = require('node:path');

Windows so với. VỊ TRÍ

Hoạt động mặc định của mô-đun

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
4 thay đổi dựa trên hệ điều hành mà Nút. ứng dụng js đang chạy. Cụ thể, khi chạy trên hệ điều hành Windows, mô-đun
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
4 sẽ cho rằng các đường dẫn kiểu Windows đang được sử dụng

Vì vậy, sử dụng

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
7 có thể mang lại kết quả khác nhau trên POSIX và Windows

Trên POSIX

Trên Windows

Để đạt được kết quả nhất quán khi làm việc với đường dẫn tệp Windows trên bất kỳ hệ điều hành nào, hãy sử dụng

Trên POSIX và Windows

Để đạt được kết quả nhất quán khi làm việc với đường dẫn tệp POSIX trên bất kỳ hệ điều hành nào, hãy sử dụng

Trên POSIX và Windows

Trên nút Windows. js tuân theo khái niệm thư mục làm việc trên mỗi ổ đĩa. Hành vi này có thể được quan sát thấy khi sử dụng đường dẫn ổ đĩa không có dấu gạch chéo ngược. Ví dụ:

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
8 có khả năng trả về một kết quả khác với
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
0. Để biết thêm thông tin, xem

┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)1

Lịch sửPhiên bảnChangesv6. 0. 0

Truyền một chuỗi không phải là đối số

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2 sẽ ném ngay bây giờ

v0. 1. 25

Đã thêm vào. v0. 1. 25

Phương thức

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
7 trả về phần cuối cùng của một
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2, tương tự như lệnh Unix
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
5. Dấu vết bị bỏ qua

Mặc dù Windows thường xử lý các tên tệp, bao gồm cả phần mở rộng tệp, theo cách không phân biệt chữ hoa chữ thường, chức năng này không. Ví dụ:

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
6 và
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
7 đề cập đến cùng một tệp, nhưng
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
5 coi phần mở rộng là một chuỗi phân biệt chữ hoa chữ thường

A được ném ra nếu

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2 không phải là một chuỗi hoặc nếu
const output = document.getElementById('output');
const filepicker = document.getElementById('filepicker');

filepicker.addEventListener('change', (event) => {
  const files = event.target.files;
  output.textContent = '';

  for (const file of files) {
    const li = document.createElement('li');
    li.textContent = file.name;
    output.appendChild(li);
  }
})
21 được đưa ra và không phải là một chuỗi

const output = document.getElementById('output'); const filepicker = document.getElementById('filepicker'); filepicker.addEventListener('change', (event) => { const files = event.target.files; output.textContent = ''; for (const file of files) { const li = document.createElement('li'); li.textContent = file.name; output.appendChild(li); } }) 22

Cung cấp dấu phân cách đường dẫn dành riêng cho nền tảng

Ví dụ: trên POSIX

Trên Windows

const output = document.getElementById('output'); const filepicker = document.getElementById('filepicker'); filepicker.addEventListener('change', (event) => { const files = event.target.files; output.textContent = ''; for (const file of files) { const li = document.createElement('li'); li.textContent = file.name; output.appendChild(li); } }) 23

Lịch sửPhiên bảnChangesv6. 0. 0

Truyền một chuỗi không phải là đối số

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2 sẽ ném ngay bây giờ

v0. 1. 16

Đã thêm vào. v0. 1. 16

Phương thức

const output = document.getElementById('output');
const filepicker = document.getElementById('filepicker');

filepicker.addEventListener('change', (event) => {
  const files = event.target.files;
  output.textContent = '';

  for (const file of files) {
    const li = document.createElement('li');
    li.textContent = file.name;
    output.appendChild(li);
  }
})
25 trả về tên thư mục của một
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2, tương tự như lệnh
const output = document.getElementById('output');
const filepicker = document.getElementById('filepicker');

filepicker.addEventListener('change', (event) => {
  const files = event.target.files;
  output.textContent = '';

  for (const file of files) {
    const li = document.createElement('li');
    li.textContent = file.name;
    output.appendChild(li);
  }
})
27 của Unix. Dấu phân cách thư mục bị bỏ qua, xem

A bị ném nếu

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2 không phải là một chuỗi

┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)41

Lịch sửPhiên bảnChangesv6. 0. 0

Truyền một chuỗi không phải là đối số

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2 sẽ ném ngay bây giờ

v0. 1. 25

Đã thêm vào. v0. 1. 25

Phương thức

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
43 trả về phần mở rộng của
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2, từ lần xuất hiện cuối cùng của ký tự (dấu chấm)
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
45 đến cuối chuỗi trong phần cuối của
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2. Nếu không có
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
45 trong phần cuối của
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2, hoặc nếu không có ký tự
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
45 nào ngoài ký tự đầu tiên của tên cơ sở của
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2 (xem
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
7), thì một chuỗi trống sẽ được trả về

A bị ném nếu

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
2 không phải là một chuỗi

┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)44

Lịch sửPhiên bảnThay đổiv19. 0. 0

Dấu chấm sẽ được thêm vào nếu nó không được chỉ định trong

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
45

v0. 11. 15

Đã thêm vào. v0. 11. 15

  • ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    46 Bất kỳ đối tượng JavaScript nào có các thuộc tính sau
  • trả lại.
  • Phương thức

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    47 trả về một chuỗi đường dẫn từ một đối tượng. Điều này trái ngược với

    Khi cung cấp các thuộc tính cho

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    46, hãy nhớ rằng có các kết hợp trong đó một thuộc tính được ưu tiên hơn thuộc tính khác

    • ┌─────────────────────┬────────────┐
      │          dir        │    base    │
      ├──────┬              ├──────┬─────┤
      │ root │              │ name │ ext │
      "  /    home/user/dir / file  .txt "
      └──────┴──────────────┴──────┴─────┘
      (All spaces in the "" line should be ignored. They are purely for formatting.)
      40 bị bỏ qua nếu cung cấp
      ┌─────────────────────┬────────────┐
      │          dir        │    base    │
      ├──────┬              ├──────┬─────┤
      │ root │              │ name │ ext │
      "  /    home/user/dir / file  .txt "
      └──────┴──────────────┴──────┴─────┘
      (All spaces in the "" line should be ignored. They are purely for formatting.)
      41
    • ┌─────────────────────┬────────────┐
      │          dir        │    base    │
      ├──────┬              ├──────┬─────┤
      │ root │              │ name │ ext │
      "  /    home/user/dir / file  .txt "
      └──────┴──────────────┴──────┴─────┘
      (All spaces in the "" line should be ignored. They are purely for formatting.)
      42 và
      ┌─────────────────────┬────────────┐
      │          dir        │    base    │
      ├──────┬              ├──────┬─────┤
      │ root │              │ name │ ext │
      "  /    home/user/dir / file  .txt "
      └──────┴──────────────┴──────┴─────┘
      (All spaces in the "" line should be ignored. They are purely for formatting.)
      43 bị bỏ qua nếu có
      ┌─────────────────────┬────────────┐
      │          dir        │    base    │
      ├──────┬              ├──────┬─────┤
      │ root │              │ name │ ext │
      "  /    home/user/dir / file  .txt "
      └──────┴──────────────┴──────┴─────┘
      (All spaces in the "" line should be ignored. They are purely for formatting.)
      44

    Ví dụ: trên POSIX

    Trên Windows

    ┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)45

    Phương thức

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    46 xác định xem
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 có phải là đường dẫn tuyệt đối không

    Nếu

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 đã cho là một chuỗi có độ dài bằng không, thì
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    49 sẽ được trả về

    Ví dụ: trên POSIX

    Trên Windows

    A bị ném nếu

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 không phải là một chuỗi

    ┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)72

    Phương thức

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    73 kết hợp tất cả các phân đoạn
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 đã cho với nhau bằng cách sử dụng dấu phân cách dành riêng cho nền tảng làm dấu phân cách, sau đó chuẩn hóa đường dẫn kết quả

    Các phân đoạn

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 có độ dài bằng 0 bị bỏ qua. Nếu chuỗi đường dẫn đã tham gia là một chuỗi có độ dài bằng 0 thì
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    76 sẽ được trả về, đại diện cho thư mục làm việc hiện tại

    A được ném nếu bất kỳ đoạn đường dẫn nào không phải là một chuỗi

    ┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)78

    Phương pháp

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    79 chuẩn hóa
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 đã cho, giải quyết các phân đoạn
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    41 và
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    76

    Khi tìm thấy nhiều ký tự phân tách đoạn đường dẫn tuần tự (e. g.

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    43 trên POSIX và
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    44 hoặc
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    43 trên Windows), chúng được thay thế bằng một phiên bản duy nhất của trình phân tách đoạn đường dẫn dành riêng cho nền tảng (
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    43 trên POSIX và
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    44 trên Windows). Dấu phân cách được giữ nguyên

    Nếu

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 là một chuỗi có độ dài bằng không, thì
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    76 được trả về, đại diện cho thư mục làm việc hiện tại

    Ví dụ: trên POSIX

    Trên Windows

    Vì Windows nhận ra nhiều dấu phân cách đường dẫn nên cả hai dấu phân cách sẽ được thay thế bằng các phiên bản của dấu phân cách ưa thích của Windows (

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    44)

    A bị ném nếu

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 không phải là một chuỗi

    const output = document.getElementById('output'); const filepicker = document.getElementById('filepicker'); filepicker.addEventListener('change', (event) => { const files = event.target.files; output.textContent = ''; for (const file of files) { const li = document.createElement('li'); li.textContent = file.name; output.appendChild(li); } }) 033

    Phương thức

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    48 trả về một đối tượng có các thuộc tính đại diện cho các phần tử quan trọng của
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2. Dấu phân cách thư mục bị bỏ qua, xem

    Đối tượng được trả về sẽ có các thuộc tính sau

    Ví dụ: trên POSIX

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)

    Trên Windows

    const output = document.getElementById('output');
    const filepicker = document.getElementById('filepicker');
    
    filepicker.addEventListener('change', (event) => {
      const files = event.target.files;
      output.textContent = '';
    
      for (const file of files) {
        const li = document.createElement('li');
        li.textContent = file.name;
        output.appendChild(li);
      }
    })
    
    2

    A bị ném nếu

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 không phải là một chuỗi

    const output = document.getElementById('output'); const filepicker = document.getElementById('filepicker'); filepicker.addEventListener('change', (event) => { const files = event.target.files; output.textContent = ''; for (const file of files) { const li = document.createElement('li'); li.textContent = file.name; output.appendChild(li); } }) 03

    Lịch sửPhiên bảnThay đổiv15. 3. 0

    Hiển thị dưới dạng

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    80

    v0. 11. 15

    Đã thêm vào. v0. 11. 15

    Thuộc tính

    const output = document.getElementById('output');
    const filepicker = document.getElementById('filepicker');
    
    filepicker.addEventListener('change', (event) => {
      const files = event.target.files;
      output.textContent = '';
    
      for (const file of files) {
        const li = document.createElement('li');
        li.textContent = file.name;
        output.appendChild(li);
      }
    })
    
    03 cung cấp quyền truy cập vào các triển khai cụ thể POSIX của các phương pháp
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2

    API có thể truy cập qua

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    83 hoặc
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    84

    ┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)85

    Lịch sửPhiên bảnChangesv6. 8. 0

    Trên Windows, các dấu gạch chéo hàng đầu cho đường dẫn UNC hiện được bao gồm trong giá trị trả về

    v0. 5. 0

    Đã thêm vào. v0. 5. 0

    Phương thức

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    86 trả về đường dẫn tương đối từ
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    87 đến
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    88 dựa trên thư mục làm việc hiện tại. Nếu
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    87 và
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    88 mỗi cái giải quyết theo cùng một đường dẫn (sau khi gọi
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    01 trên mỗi cái), một chuỗi có độ dài bằng 0 được trả về

    Nếu một chuỗi có độ dài bằng 0 được chuyển thành

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    87 hoặc
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    88, thì thư mục làm việc hiện tại sẽ được sử dụng thay cho các chuỗi có độ dài bằng 0

    Ví dụ: trên POSIX

    Trên Windows

    A bị ném nếu

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    87 hoặc
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    88 không phải là một chuỗi

    ┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)07

    Phương thức

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    01 giải quyết một chuỗi các đường dẫn hoặc đoạn đường dẫn thành một đường dẫn tuyệt đối

    Trình tự các đường dẫn nhất định được xử lý từ phải sang trái, với mỗi

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 tiếp theo được thêm vào trước cho đến khi một đường dẫn tuyệt đối được tạo. Chẳng hạn, với trình tự các đoạn đường dẫn.
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    10,
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    11,
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    12, gọi
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    13 sẽ trả về
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    14 vì
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    15 không phải là đường dẫn tuyệt đối nhưng
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    16 là

    Nếu sau khi xử lý tất cả các phân đoạn

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 đã cho, một đường dẫn tuyệt đối vẫn chưa được tạo, thì thư mục làm việc hiện tại sẽ được sử dụng

    Đường dẫn kết quả được chuẩn hóa và các dấu gạch chéo ở cuối sẽ bị xóa trừ khi đường dẫn được giải quyết đến thư mục gốc

    Các phân đoạn

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 có độ dài bằng 0 bị bỏ qua

    Nếu không có phân đoạn

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 nào được chuyển,
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    01 sẽ trả về đường dẫn tuyệt đối của thư mục làm việc hiện tại

    A được ném nếu bất kỳ đối số nào không phải là một chuỗi

    const output = document.getElementById('output'); const filepicker = document.getElementById('filepicker'); filepicker.addEventListener('change', (event) => { const files = event.target.files; output.textContent = ''; for (const file of files) { const li = document.createElement('li'); li.textContent = file.name; output.appendChild(li); } }) 28

    Cung cấp trình phân tách đoạn đường dẫn dành riêng cho nền tảng

    Ví dụ: trên POSIX

    Trên Windows

    Trên Windows, cả dấu gạch chéo xuôi (_______943) và dấu gạch chéo ngược (

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    44) đều được chấp nhận làm dấu phân cách đoạn đường dẫn;

    ┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)27

    Chỉ trên các hệ thống Windows, trả về giá trị tương đương cho

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 đã cho. Nếu
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 không phải là một chuỗi, thì
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 sẽ được trả về mà không cần sửa đổi

    Phương pháp này chỉ có ý nghĩa trên các hệ thống Windows. Trên các hệ thống POSIX, phương thức này không hoạt động và luôn trả về

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2 mà không cần sửa đổi

    ┌─────────────────────┬────────────┐ │ dir │ base │ ├──────┬ ├──────┬─────┤ │ root │ │ name │ ext │ " / home/user/dir / file .txt " └──────┴──────────────┴──────┴─────┘ (All spaces in the "" line should be ignored. They are purely for formatting.)4

    Lịch sửPhiên bảnThay đổiv15. 3. 0

    Tiếp xúc như

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    33

    v0. 11. 15

    Đã thêm vào. v0. 11. 15

    Thuộc tính

    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    4 cung cấp quyền truy cập vào các triển khai dành riêng cho Windows của các phương thức
    ┌─────────────────────┬────────────┐
    │          dir        │    base    │
    ├──────┬              ├──────┬─────┤
    │ root │              │ name │ ext │
    "  /    home/user/dir / file  .txt "
    └──────┴──────────────┴──────┴─────┘
    (All spaces in the "" line should be ignored. They are purely for formatting.)
    2

    Làm cách nào để lấy tên tệp từ đường dẫn trong javascript?

    Giải thích .
    var url = cửa sổ. địa điểm. tên đường dẫn;
    tên tệp var = url. chuỗi con (url. lastIndexOf('/')+1);
    var url = cửa sổ. địa điểm. tên đường dẫn; . chuỗi con (url. lastIndexOf('/')+1);

    Làm cách nào để lấy tên tệp từ đường dẫn trong nút?

    Đường dẫn . phương thức basename() trả về phần tên tệp của đường dẫn tệp.

    Làm cách nào để lấy tên tệp từ chuỗi javascript?

    Sử dụng phương thức split và pop() . Sử dụng phương thức pop() của mảng để lấy phần tử cuối cùng của mảng. Tách lại Chuỗi bằng dấu gạch chéo ngược bằng phương thức tách. Sử dụng pop() để lấy phần tử cuối cùng của mảng sẽ dẫn đến FileName.

    Làm cách nào để đọc tệp từ đường dẫn cục bộ trong javascript?

    Đọc nội dung của tệp bằng đối tượng FileReader. .
    Bước 1 - Cho phép người dùng chọn tệp. <. --.
    Bước 2 — Đọc Siêu dữ liệu Tệp (Tên, Loại & Kích thước) bằng Thuộc tính của Đối tượng Tệp. Tệp do người dùng chọn có thể được truy cập dưới dạng đối tượng Tệp trong Javascript. .
    Bước 3 — Đọc nội dung tệp bằng đối tượng FileReader