This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

name

Summary

The name of the file; on getting, this must return the name of the file as a string. There are numerous file name variations on different systems; this is merely the name of the file, without path information. On getting, if user agents cannot make this information available, they must return the empty string.

Property of apis/file/Fileapis/file/File

Syntax

Note: This property is read-only.

var result = File.name;

Return Value

Returns an object of type StringString

Examples

This example lets you select one or more files, then reports each file’s name and last modified date/time.

<input type="file" multiple id="myfileinput"><br/>
<input type="button" value="Show file names and last modified dates" onclick="shownd()">
<p>. . .</p>
<script>
function shownd() {
  var fileinp = document.getElementById("myfileinput");
  var filelist = fileinp.files;
  alert(filelist.length);
  for (var i = 0; i < filelist.length; i++) {
    alert(filelist[i].name + " was last modified: " + filelist[i].lastModifiedDate);
  }
}
</script>

Notes

This property returns the name of the file as a string. There are numerous file name variations on different systems; this property is merely the name of the file, without path information. If the file name cannot be obtained, name contains an empty string.

Related specifications

W3C File API Specification
W3C Working Draft

Attributions