FileSystemObject object, filesystemobject
To implement file operations in javascript, FileSystemobject objects are primarily used.
It is very easy to program with FileSystemObject object. The steps are as follows:
1. Create a FileSystemObject object
Var fso = new ActiveXObject ("Scripting. FileSystemObject ");
2. After creating an object instance, you can use the object-related methods.
For example, create a text file:
<script language="javascript"> var fso = new ActiveXObject("Scripting.FileSystemObject"); var newFileObject = fso.CreateTextFile("c:\\boat.txt", true); </script>
3. Access Object Attributes
To access the relevant properties of an object, you must first create a handle pointing to the object:
GetDrive obtains the drive information, GetFolder obtains the folder information, and GetFile obtains the file information.
In the following code, textfile is the handle pointing to the file c: \ boat.txt:
var fso = new ActiveXObject("Scripting.FileSystemObject");var textfile = fso.GetFile("c:\\boat.txt");alert("File last modified: " + textfile.DateLastModified);
For objects created using the create method, you can directly use the name of the handle created using the create method:
var fso = new ActiveXObject("Scripting.FileSystemObject");var textfile = fso.createtextfile("c:\\boat.txt",true");alert("File last modified: " + textfile.DateLastModified);