Javascript FileSystemObject (FSO) GetFileName method provides the functionality to get the file name or folder name from the specified path. FSO GetFileName method works like GetBaseName method that returns the name of the file or folder from the specified path. The only difference is that the GetFileName method returns the file name with its extension whereas GetBaseName method returns file name without file extension.
Syntax for Javascript FSO GetFileName method
fso.GetFileName( path );
As shown in the above syntax of FSO GetFileName method it accepts only one parameter as path of the file or folder.
Example of FSO GetFileName method
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// returns the file name or folder name from the specified path
var fName = fso.GetFileName("c:\\Temp\\myFolder\\file.txt");
document.write(fName);
document.write("<br />");
fName = fso.GetFileName("c:\\Temp\\myFolder");
document.write(fName);
document.write("<br />");
fso = null;
// Output:
// file.txt
// myFolder
</script>
Continue to next tutorial: Javascript FSO GetFolder Method to learn how to get the directory information.