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

BCD tables only load in the browser

See also