Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method. ShortPath property returns the short path and name of the specified file or folder according to the 8.3 naming convention of file system. According to 8.3 naming system file names or folder names must have at most 8 characters to name them and not more than 3 characters to specify their extensions. This naming convention was introduced to make all types of file systems could share the compatible naming conventions to read the long file names. Old DOS or FAT based systems work on 8.3 naming convention whereas modern Computer systems running on NT based platforms are capable of reading long file names. ShortPath property of FSO enables you to get the short path, file name and folder names according to 8.3 naming standards that could be used as platform independent file names.
Syntax for Javascript FSO ShortPath Property
fileObj.ShortPath // or folderObj.ShortPathÂ
fileObj object has been used in the first syntax that could be retrieved from GetFile method which further provides the access to ShortPath property and returns the short path and short name of the specified file. Similarly folderObj used in the second syntax could be retrieved from GetFolder method which also provides the access to the ShortPath property and returns the short path and name of the specified folder.
Example 1
File object to get the value of ShortPath Property
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// object created for file object returned by GetFile method
var fileObj = fso.GetFile("C:\\Temp\\documents_folder\\New Text Document.txt");
document.write("<b>File Path : </b>" + fileObj.Path);
document.write("<br />");
document.write("<b>File ShortPath : </b>" + fileObj.ShortPath);
document.write("<br />");
// Output
// File Path : C:\Temp\documents_folder\New Text Document.txt
// File ShortPath: C:\Temp\DOCUME~1\NEWTEX~1.TXT
</script>
Example 2
Folder object to get the value of ShortPath Property
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// object created for folder object returned by GetFolder method
var folderObj = fso.GetFolder("C:\\Temp\\documents_folder");
document.write("<b>Folder Path : </b>" + folderObj.Path);
document.write("<br />");
document.write("<b>Folder ShortPath : </b>" + folderObj.ShortPath);
document.write("<br />");
// Output:
// Folder Path : C:\Temp\documents_folder
// Folder ShortPath : C:\Temp\DOCUME~1
</script>
Continue to next tutorial: Javascript FSO Size Property to learn how to get the size of the specified file or folder.