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.

length

Summary

length returns the number of files in the FileList object. If there are no files, this attribute must return 0.

Property of apis/file/FileListapis/file/FileList

Syntax

Note: This property is read-only.

var result = FileList.length;

Return Value

Returns an object of type unsigned longunsigned long

Examples

This example lets you select one or more files, then uses the filelist length to report each filelist item’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.item(i).name + " was last modified: " + filelist.item(i).lastModifiedDate);
  }
}
</script>

Notes

Returns the number of files that are selected and available on the FileList object. This value can be greater than or equal to 1 if multiple file selection is enabled (typically via the multiple attribute on the input element). If no files have been selected, 0 is returned.

Related specifications

W3C File API Specification
W3C Working Draft

Attributions