Javascript FileSystemObject (FSO) GetBaseName method provides the functionality to get the base of the specified file or folder. If path specified in the GetBaseName method contains file name at the end then it returns the name of the specified file except its extension and absolute path. If path specified in the GetBaseName method end with folder name then it returns the name of the folder at the end of the path.
Syntax for Javascript FSO GetBaseName Method
fso.GetBaseName( Path );
As shown in the above syntax of FSO GetBaseName method, it accepts only one parameter as path of any file or folder whose base name is to be retrieved.
Example of FSO GetBaseName Method
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// returns the base name of the specified file
var fbaseName = fso.GetBaseName("C:\\Temp\\myFolder\\file.txt");
document.write(fbaseName);
document.write("<br />");
// returns the base name of the specified folder
fbaseName = fso.GetBaseName("C:\\Temp\\myFolder");
document.write(fbaseName);
document.write("<br />");
fso = null;
// Output:
// file
// myFolder
</script>
Continue to next tutorial: Javascript FileSystemObject GetDrive method with Properties to learn how to access the specified drive.