JavaScript | WebAPI | File | File.name Property
The File.name property is an inbuilt function of File WebAPI which gives the name of the file represented by a file object. The path of file is excluded from this property for security reasons.
Syntax:
var name = file.name;
Return Value: It returns a string, containing the name of the file without path.
Example:
<!DOCTYPE html> <html> <head> <title> WebAPI File.name Property </title> <style> #main { padding: 10px; width: 300px; border: 1px solid green; text-align:center; font-size:22px; } </style> </head> <body> <div id = "main"> <div>GeeksForGeeks</div> <div>file.name</div> <input type = "file" multiple onchange = "myGeeks(this)"> </div> <script type="text/javascript"> function myGeeks(input_file) { var files = input_file.files; for (var i = 0; i < files.length; i++) { alert("Name of file:" + files[i].name); } } </script> </body> </html> |
Output:

Supported Browsers: The browser supported by WebAPI File.name property are listed below:
- Edge 12
- Google Chrome 13
- Firefox 3.6
- Opera 16
- Internet Explorer 10
- Safari
Reference: https://developer.mozilla.org/en-US/docs/Web/API/File/name
Recommended Posts:
- JavaScript | WebAPI | File | File.size Property
- JavaScript | WebAPI | File | File.type Property
- How to include a JavaScript file in another JavaScript file ?
- How to get file extensions using JavaScript?
- How to get the file name from full path using JavaScript ?
- Javascript | Program to read text File
- How to trim a file extension from string using JavaScript ?
- JavaScript | Program to write data in a text File
- How to reset input type = "file" using JavaScript/jQuery?
- Validation of file size while uploading using JavaScript / jQuery
- JavaScript | Math.LN2 property
- How to remove CSS property using JavaScript?
- Javascript | MouseEvent which Property
- JavaScript | Error name Property
- JavaScript | Infinity Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



