Javascript FSO GetFile Method

Updated on 26 Mar 2012,
Published on 14 Oct 2008

Javascript FileSystemObject (FSO) GetFile method provides the functionality to access the properties and methods associated with file object. FSO GetFile method returns the File object that further provides the access to all such properties and methods. GetFile method allows you to access the properties such as Name, Date last accessed, date last modified, path, parent folder etc. Methods supported by GetFile method are copy, move, delete, open text file as text stream etc. GetFile method targets the specified file and performs each action on it based on the applied method. 

Syntax for Javascript FSO GetFile Method

fso.GetFile( filePath );

As shown in the above syntax of FSO GetFile method it accepts only 1 parameter as filePath along with its name.

Example of FSO GetFile Method

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // returns the file object associated with the specified file
    var fileObj = fso.GetFile("C:\\Temp\\myFolder\\File.txt");
    document.write(fileObj.Name);

    fso = null;

    // Output: 
    // file.txt
</script>

FSO File Object Properties

  1. Attributes: gets or sets the attributes of the file.
  2. DateCreated: returns the date and time when the file was created.
  3. DateLastAccessed: returns the date and time when the file was last accessed.
  4. DateLastModified: returns the date and time when the file was last modified.
  5. Drive: returns the drive letter retrieved from the path of the file.
  6. Name: returns the name of the file.
  7. ParentFolder: returns the name of the parent folder.
  8. Path: returns the complete path of the file.
  9. ShortName: returns the short name of the file according to 8.3 naming convention of file system.
  10. ShortPath: returns the short path of the file according to 8.3 naming convention of file system.
  11. Size: returns the size of the file in bytes.
  12. Type: returns the type of the file. 

FSO File Object Methods

  1. Copy: copies the file to the specified location.
  2. Delete: deletes the file
  3. Move: moves the file to the specified location.
  4. OpenAsTextStream: opens the file as textstream and allows reading, writing or appending it.

Continue to next tutorial: Javascript FSO GetFileName Method to learn how to get the file from the specified path.

0 Responses to "Javascript FSO GetFile Method"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers