JavaScript Tutorial/MS JScript/File
Содержание
File
The File object provides access to all the properties of a file.
Property/Method Description Attributes Refers to the attributes of the file Copy() Copies a file from one location to another DateCreated Returns the date a file was created DateLastAccessed Returns the date a file was last accessed DateLastModified Returns the date a file was last modified Delete() Removes a file Drive Returns the drive on which a file exists Move() Moves a file from one location to another Name Returns the name for a file OpenAsTextStream() Opens a text stream for a file ParentFolder Returns the parent folder name for a file Path Returns the path to a file ShortName Returns the shortname of the file ShortPath Returns the shortpath of the file Size Returns the size of a file Type Returns the file type
<source lang="javascript">
<html>
<body> <script language="JavaScript"> </script> </body> </html></source>
File.Attributes
Syntax
<source lang="javascript">
file.Attributes[newattributes]</source>
The Attributes property is used to determine and set the attributes of a file.
This property is an array that takes the optional parameter newattributes to set any new attributes.
Attributes can be read/write or read-only.
Attribute properties Property Description 0 Specifies a Normal file. No attributes set. 1 Specifies that a file is a Read-only file. Attribute is read/write. 2 Specifies that a file is Hidden. Attribute is read/write. 4 Refers to a system file. Attribute is read/write. 8 Refers to the disk drive volume label. Attribute is read-only. Refers to a folder in a directory. Attribute is read-only. 32 Specifies that a file has changed since the last backup. Attribute is read/write. 64 Refers to a link or shortcut. Attribute is read-only. 128 Refers to the disk drive volume label. Attribute is read-only.
File.Copy()
Syntax
<source lang="javascript">
file.Copy(destination, overwrite)</source>
File.DateCreated
The DateCreated property is used to get the date in which the file was created.
<source lang="javascript">
<html>
<BODY> <script language="JScript"> </script> Get the date that mytest.txt was created. <form name="myForm"> <INPUT type="Button" value="Get Date" onClick="get()"> </form> </BODY> </html></source>
File.DateLastAccessed
The DateLastAccessed property is used to find out the last date that the file was accessed.
<source lang="javascript">
<html>
<BODY> <script language="JScript"> </script> Get the date that mytest.txt was last accessed. <form name="myForm"> <INPUT type="Button" value="Get Date" onClick="get()"> </form> </BODY> </html></source>
File.DateLastModified
The DateLastModified property returns the date when the file was last modified.
<source lang="javascript">
<html>
<BODY> <script language="JScript"> </script> Get the date that mytest.txt was last modified. <form name="myForm"> <INPUT type="Button" value="Get Date" onClick="get()"> </form> </BODY> </html></source>
File.Delete()
The Delete() method is used to delete a specified file.
<source lang="javascript">
<html>
<body> <script language="JScript"> </script> Delete file "mytest.txt". <form name="myForm"> <input type="Button" vvalue="Delete File" onClick="remove()"> </form> </body> </html></source>
File.Move()
Syntax
<source lang="javascript">
file.Move(destination)</source>
File.Name
The Name property is used to either set or get the name of a file object.
<source lang="javascript">
<html>
<BODY> <script language="JScript"> </script> <form name="myForm"> <INPUT type="Button" value="Get Name" onClick="get()"> </form> </BODY> </html></source>
File.ParentFolder
The ParentFolder property determines the parent folder from which the file was obtained.
<source lang="javascript">
<html>
<body> <script language="JScript"> </script> Click to get the name of the parent folder <form name="myForm"> <input type="Button" value="Get Parent Folder" onClick="get()"> </form> </body> </html></source>
File.Path
The Path property gets the path for a specified file.
<source lang="javascript">
<html>
<body> <script language="JScript"> </script> <form name="myForm"> <input type="Button" value="Get Path" onClick="getPath()"> </form> </body> </html></source>
File.ShortName
The ShortName property returns the short name used by programs that require the earlier 8.3 naming convention.
<source lang="javascript">
<html>
<body> <script language="JScript"> </script> <form name="myForm"> <input type="Button" value="Get Shortname" onClick="get()"> </form> </body> </html></source>
File.ShortPath
The ShortPath property returns the short path used by programs that require the earlier 8.3 naming convention.
<source lang="javascript">
<html>
<BODY> <script language="JScript"> </script> <form name="myForm"> <INPUT type="Button" value="Get Shortpath" onClick="get()"> </form> </BODY> </html></source>
File.Size
The Size property returns the size of the specified file.
<source lang="javascript">
<html>
<BODY> <script language="JScript"> </script> <form name="myForm"> type=value=<input type="Button" value="Get File Size" onClick="get()"> </form> </body> </html></source>
File.Type
The Type property is used to get information pertaining to the type of file.
<source lang="javascript">
<html>
<body> <script language="JScript"> </script> <form name="myForm"> <input type="Button" value="Get File Type" onClick="get()"> </form> </body> </html></source>