dom / latest / file / name.html /

File.name

Returns the name of the file represented by a File object. For security reasons, the path is excluded from this property.

Value

A string, containing the name of the file without path, such as "My Resume.rtf".

Examples

<input type="file" multiple onchange="processSelectedFiles(this)">

<div id="output"></div>
const output = document.querySelector("#output");
function processSelectedFiles(fileInput) {
  let files = fileInput.files;
  output.textContent = "List of Selected Files:";

  for (let i = 0; i < files.length; i++) {
    output.textContent += `\nFilename: ${files[i].name}`;
  }
}

Result

Specifications

Specification
File API
# dfn-name

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
name
13
12
3.6
10
≤15
7
≤37
18
4
≤14
7
1.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/File/name