11.2 File System Object

The File System object provides the ability to access a server's file system. You can process folders and files using this object. The full path is required to access the DOS files.

11.2.1 GetServerFolder property

Returns the folder object that contains the server executable (server.exe).

Syntax

 Object.GetServerFolder
 

Type

Folder object.

Attributes

Read-only.

Examples

This example returns NWserver as the file object as the server executable (server.exe) is located in C:\NWserver.

 <% Set FSO = CreateObject("Scripting.FileSystemObject") %>
 <% Set Folder = FSO.GetServerFolder %>
 <% Response.Write (Folder.Name) %>
 

11.2.2 BuildPath method

Appends a file name to an existing path.

Syntax

 object.BuildPath(
    Path As String
    Name As String)
 

Parameter

Path
Existing path (absolute or relative) to which a file name is appended.
Name
File name that is going to be appended to the existing path.

Return Value

String.

Example

This example appends the file name FSO.TXT to the directory specified.

 <% Set FSO = CreateObject("Scripting.FileSystemObject") 
 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Appends the file fso.txt to the specified directory path 
 Response.Write "FSO.BuildPath("Sys:\readme","fso.txt") %>
 

NOTE:The argument in the CreateObject call may also be the UCX:File SystemObject.

11.2.3 CopyFile method

Copies a file from one directory to another.

Syntax

 object.CopyFile(
      Source As String,
      Destination As String [,
      OverWrite As Boolean])
 

Parameters

Source
Path specifying the file to copy.
Destination
Path specifying the destination folder to copy a file specified in Source.
Overwrite
If TRUE, the folder and the existing files are overwritten. The default is TRUE.

Return Value

Boolean.

Remarks

CopyFile will fail if the destination directory has read-only attributes set, regardless of the value of the Overwrite parameter.This will work only for NetWare files.

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

Example

This example copies TEST1.TXT from Sys:\nsn\user directory to Sys:\nsn\util directory. The file TEST1.TXT file should be existing in the specified directory.

 	<% Set FSO = CreateObject("Scripting.FileSystemObject") %>
 		<% ’Copies the file from user to util directory and overwrites
 if already existing under util directory
 		Response.write FSO.CopyFile
 ("sys:\nsn\user\test1.txt","sys:\nsn\util\",TRUE) %> 
 

11.2.4 CopyFolder method

Copies a folder from one location to another along with the subdirectories.

Syntax

 object.CopyFolder(
      Source As String,
      Destination As String [,
      OverWrite As Boolean])
 

Parameters

Source
Path specifying the files to copy.
Destination
Path specifying the destination folder to copy the file or files specified in Source.
Overwrite
If TRUE, the folder and the existing files are overwritten. The default is TRUE.

Return Value

Boolean.

Remarks

CopyFolder will fail if the destination directory has read-only attributes set, regardless of the value of the Overwrite parameter.

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

Example

This example copies folder \TEMP from Sys:\nsn\user\ to Sys:\nsn\util\. Ensure that the folder is existing. Else the script will give an error.

 	<% Set FSO = CreateObject("Scripting.FileSystemObject") %>
 		<% ’Copies the folder TEMP from user directory to UTIL
 directory
 		Response.Write
 FSO.CopyFolder("sys:\nsn\user\temp","sys:\nsn\util\",TRUE)
 %>
 

11.2.5 CreateFolder method

Creates a folder with the specified name.

Syntax

 object.CreateFolder(
    FolderName As String)
 

Parameters

FolderName
Name of the folder to create.

Return Value

Boolean.

Remarks

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

Example

This example creates the folder named \SAMPLE in Sys:\NSN.

 <% Set FSO = CreateObject("Scripting.FileSystemObject") %>
 		<% ’Creates a folder SAMPLE in NSN under Sys:
 		Response.Write FSO.CreateFolder("sys:\nsn\sample") %> 
 

11.2.6 CreateTextFile method

Creates a specified file name and returns a TextStream object that can be used to read from or write to a file.

Syntax

 object.CreateTextFile(
      FileName As String
      [, Overwrite As Boolean
      [, Unicode As Boolean]])
 

Parameters

FileName
Name of the file to create.
Overwrite
If set to TRUE, the file can be overwirtten. Default is FALSE.
Unicode
The value is TRUE if the file is created as Unicode, FALSE, if it is created as an ASCII file. By default the file is generated in ASCII.

Return Value

Section 11.3, TextStream.

Remarks

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

Example

This example creates or overwrites an ASCII text file named TEST.TXT and returns a TextStream object.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Creates a text file
 Set TextStream =FSO.CreatetextFile("sys:\nsn\user\test.txt")  
 ’Checks whether the file pointer is at the end of the line
 Response.Write TextStream.AtEndOfLine 
 Textstream.Close() %>
 

11.2.7 DeleteFile method

Deletes a specified file.

Syntax

 object.DeleteFile(
    FileSpec As String,
    [,Force As Boolean])
 

Parameters

FileSpec
Name of the file to delete.
Force
If set to TRUE, the files with read-only attribute are deleted. Default is FALSE.

Return Value

Boolean.

Remarks

The Force parameter will work only for NetWare files.

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

Example

This example deletes TEST1.TXT, which has Read-only attributes.

 	<% Set FSO = CreateObject("Scripting.FileSystemObject") %>
 		<% ’Deletes the file from util directory
 		Response.write FSO.DeleteFile("Sys:\nsn\util\test1.txt",TRUE) %> 
 

11.2.8 DeleteFolder method

Deletes a specified folder along with the subdirectories and their content.

Syntax

 object.DeleteFolder(
    FolderSpec As String
    [, Force As Boolean])
 

Parameters

FolderSpec
The name of the folder to delete.
Force
If set to TRUE, the folders with read-only property are deleted. Default is FALSE.

Return Values

Boolean.

Remarks

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

Example

This example deletes the folder \SAMPLE.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 response.Write FSO.DeleteFolder("Sys:\nsn\sample", TRUE) %> 
 

11.2.9 FileExist method

Returns TRUE if a specified file exists.

Syntax

 object.FileExist(
    FileSpec As String)
 

Parameters

FileSpec
The file name that is being checked, to determine if it exists.

Return Value

Boolean.

Example

This example returns TRUE if the file named FILE1.BAS exists in Sys:\nsn\user directory.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns FALSE as the specified file does not exist
 Response.Write FSO.FileExists("sys:\nsn\user\file1.bas") %> 
 

11.2.10 FolderExist method

Returns TRUE if a specified folder exists.

Syntax

 object.FolderExist(
    FolderSpec As String)
 

Parameters

FolderSpec
The folder name that is being checked, to determine if it exists.

Return Value

Boolean.

Example

This example returns TRUE, if the directory named \TEMP exists under Sys:\nsn\user directory.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns TRUE if the specified folder exists
 Response.Write FSO.FolderExists("sys:\nsn\user\Temp") %> 
 

See Also

11.2.11 GetAbsolutePathName method

Returns a complete path from the path details specified.

Syntax

 object.GetAbsolutePathName (
    PathSpec As String)
 

Parameters

PathSpec
The path details (with absolute or relative path).

Return Value

String.

Example

This example gets the complete path of the folder \USER.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns the absolute path name of the USER directory
 Response.Write FSO.GetAbsolutePathName("\user") %> 
 

11.2.12 GetBaseName method

Returns a string containing the base name of the file (without the extension), or folder in the path specified.

Syntax

 object.GetBaseName(
    Path As String)
 

Parameters

Path
The path specification of the file or folder whose base name is to be returned. (either absolute or relative)

Return Value

String.

Example

This example returns Test, which is the base name of the file TEST.TXT.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns the Base name of the file TEST.TXT
 Response.Write FSO.GetBaseName("Sys:\nsn\user\test.txt") %> 
 

11.2.13 GetExtensionName method

Returns a string containing the extension name of the last component in a path.

Syntax

 object.GetExtensionName(
    Path As String)
 

Parameters

Path
The file or folder name whose extension is to be returned.

Return Value

String.

Example

This example returns the value "TXT", which is the extension of the file TEST.TXT.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns the extension name of the file TEST.TXT
 Response.Write
 FSO.GetExtensionName("Sys:\nsn\user\test.txt") %>> 
 

11.2.14 GetFile method

Returns a file object corresponding to the files specified in the path.

Syntax

 object.GetFile(
    FileSpec As String)
 

Parameters

FileSpec
Path of the specific file.

Return Value

Section 11.4, File.

Example

See sample in Example.

See Also

11.2.15 GetFileName method

Returns a string containing the file name from the specified path.

Syntax

 object.GetFileName(
    PathSpec As String)
 

Parameters

PathSpec
The path to a specific file.

Return Value

String.

Example

This example returns the TEST.TXT.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns the file name of the file TEST.TXT
 Response.Write FSO.GetFileName("Sys:\nsn\user\test.txt") %>
 

11.2.16 GetFolder method

Returns a folder object corresponding to the folder in the specified path.

Syntax

 object.GetFolder
    FolderSpec As String)
 

Parameters

FolderSpec
The path to the specific folder.

Return Value

Folder.

Example

See sample in Example.

See Also

11.2.17 GetParentFolderName method

Returns a string containing the name of the parent folder or file in the specified path.

Syntax

 object.GetParentFolderName(
    Path As String)
 

Parameters

Path
Path of the file or folder whose parent folder name is to be returned.

Return Value

String.

Example

This example returns NSN, which is the parent of \USER.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns name of the parent folder
 Response.Write FSO.GetParentFolderName("Sys:\nsn\user") %>
 

11.2.18 GetTempName method

Returns a randomly generated temporary file or folder name that is useful for performing operations that require a temporary file or folder.

Syntax

 object.GetTempName
 

Parameters

None.

Return Value

String.

Example

This example returns the temp name of a file or folder.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Returns the randomly generated temporary file
 Response.Write FSO.GetTempName %> 
 

11.2.19 MoveFile method

Moves a file from one location to another.

Syntax

 object.MoveFile(
   Source As String,
   Destination As String)
 

Parameters

Source
The path of the file to be moved.
Destination
The path where the file are to be moved.

Return Value

Boolean.

Remarks

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

Example

This example moves TEST1.TXT from Sys:\nsn\user to Sys:\nsn\util directory.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Moves the file TEST1.TXT from USER to UTIL directory
 Response.Write
 FSO.MoveFile("sys:\nsn\user\test1.txt","sys:\nsn\util\") %> 
 

11.2.20 MoveFolder method

Moves one or more folders from one location to another.

Syntax

 object.MoveFolder(
   Source As String, 
   Destination As String)
 

Parameters

Source
The path of the folder or folders to be moved.
Destination
The path where the folder or folders are to be moved.

Return Value

Boolean.

Remarks

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

Example

This example moves \NSN\USER\TEMP to \NSN\UTIL and the resultant path would be SYS:\NSN\UTIL.

 <% Set FSO = CreateObject("Scripting.FileSystemObject")
 ’Moves the folder TEMP from USER to UTIL directory
 Response.Write
 FSO.MoveFolder("sys:\nsn\user\temp","sys:\nsn\util\") %> 
 

11.2.21 OpenTextFile 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.OpenTextFile 
   (FileName As String [,
    I/OMode As Integer [,
    Create As Boolean [,
    Format As Integer]]])
 

Parameters

FileName
Name of the file to open.
IOMode
Indicates input/output mode. Can be one of three constants: ForReading, ForWriting, or ForAppending. See File Open Constants.
Create
Boolean. Set to TRUE to create a new file if the file does not exists.
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 Value

Section 11.3, TextStream.

Remarks

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