11.4 File

Provides access to all the properties of a file.

11.4.1 Attributes property

Sets or returns the attributes of a file.

Type

Integer. (See Attribute Constants)

Syntax

 object.Attributes=[newAttributes As Integer]
 

Attributes

Read-write.

Remarks

newAttributes is a new value for the attributes of a specified object.Attributes can be set for NetWare files.

Example

See sample in Example.

11.4.2 DateCreated property

Returns the date and time when the specified file was created.

Syntax

 object.DateCreated
 

Type

Date.

Attributes

Read-only.

Example

See sample in Example.

11.4.3 DateLastAccessed property

Returns the date and time when the specified file was last accessed.

Syntax

 object.DateLastAccessed
 

Type

Date.

Attributes

Read-only.

Example

See sample in Example.

11.4.4 DateLastModified property

Returns the date and time when the specified file was last modified.

Syntax

 object.DateLastModified
 

Type

Date.

Attributes

Read-only.

Example

See sample inExample.

11.4.5 Name property

Sets or returns the name of a specified file.

Syntax

 object.Name[=newname]
 

Type

String.

Attributes

Read-write.

Remarks

newname is the new name of the specified object.

Example

See sample in Example.

11.4.6 ParentFolder property

Returns the folder object for the parent of the specified file.

Syntax

 object.ParentFolder
 

Attributes

Read-only.

Example

See sample in Example.

11.4.7 Path property

Returns the path for a specified file.

Syntax

 object.Path
 

Type

String.

Attributes

Read-only.

Example

See sample in Example.

11.4.8 ShortName property

Returns the short name of a file used by the programs in 8.3 naming convention.

Syntax

 object.ShortName
 

Type

String.

Attributes

Read-only.

Example

See sample in Example.

11.4.9 ShortPath property

Returns the short path in 8.3 naming convention.

Syntax

 object.ShortPath
 

Type

String.

Attributes

Read-only.

Example

See sample in Example.

11.4.10 Size property

Returns the size of the specified file in bytes.

Syntax

 object.Size
 

Type

Long.

Attributes

Read-only.

Example

See sample in Example.

11.4.11 Copy method

Copies a specified file from one location to another.

Syntax

 object.Copy( 
    Destination As String 
    [, Overwrite As Boolean])
 

Parameters

Destination
Destination where the file is to be copied.
Overwrite
Boolean. If set to TRUE, the existing files are overwritten.

Return Values

Boolean. Returns TRUE if the files are successfully copied to the specified location.

Remarks

The existing folders can be over-written only in NetWare files.

If the Web-based script is not authenticated to eDirectory with appropriate rights, an error is returned.

Example

See sample in Example.

11.4.12 Delete method

Deletes a specified file.

Syntax

 object.Delete([ 
    Force As Boolean])
 

Parameters

Force
Boolean. Set to TRUE if the files with read-only attribute are to be deleted.

Return Values

Boolean. Returns TRUE if the file is successfully deleted.

Remarks

The existing folders with read-only attributes can be deleted only in NetWare files.

If the Web-based script is not authenticated to eDirectory with appropriate rights, an error is returned.

Example

This example deletes FILETEST.TXT, even if read-only attributes are set. The file should exist in the specified directory.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns the file object
 Set File =  FSO.GetFile("Sys:\nsn\util\FileTest.txt")
 Response.Write File.Delete (TRUE) %>
 

11.4.13 Move method

Moves a specified file from one location to another.

Syntax

 object.Move( 
    Destination As String)
 

Parameters

Destination
Location where the file is to be moved.

Return Values

Boolean. Returns TRUE if the files are successfully moved.

Remarks

If the Web-based script is not authenticated to eDirectory with appropriate rights, an error is returned.

Example

This example moves the file FILETEST.TXT from Sys:\nsn\user to Sys:\nsn\util\FILETEST.BAS.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns the file object
 Set File =  FSO.GetFile("Sys:\nsn\user\FileTest.txt")
 Response.Write File.Move ("sys:\nsn\util\filetest.bas") %>
 

11.4.14 OpenAsTextStream method

Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.

Syntax

 object.OpenAsTextStream([
    IOMode As Integer [,
    Format As Integer]])
 

Parameters

IOMode
Indicates input/output mode. Can be one of three constants: ForReading, ForWriting, or ForAppending.
Format
One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII. (See File Open Constants).

Return Values

Section 11.3, TextStream.

Example

This example opens TEST1.TXT and returns the all the properties related to that file. It also opens the file as a text file for editing.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 
 ’Returns the file object
 Set File =  FSO.GetFile("Sys:\nsn\user\sample.txt")
 
 ’Renames the file to FILETEST.TXT
 File.Name = "FileTest.txt" %>
 
 <% ’Returns the attributes of the set file object
 Response.write File.Attributes%><br>
 
 <% ’Returns the file creation date
 Response.write File.DateCreated %><br>
 
 <% ’Returns the last accessed date
 Response.Write File.DateLastAccessed %> <br>
 
 <% ’Returns last modified date
 Response.Write File.DateLastModified %><br>
 
 <% ’Returns the name of the parent folder
 Response.Write File.ParentFolder %><br>
 
 <%’Returns the shortname of the file
  Response.Write File.ShortName %><br>
 
 <% ’Copies the file to UTIL directory
  Response.Write File.Copy ("Sys:\nsn\util") %><br>
 
 <%’Returns the shortpath of the file
  Response.Write File.ShortPath %><br>
 
 <%’Returns the file size
  Response.Write File.Size %><br> 
 <% ’Sets the file as a text file in edit mode
 Set text = File.OpenAsTextStream(8) 
 text.write ("Sample script")
 text.readall() %>