[ LiB ] |
In addition to the objects that make up the WSH object model, your JScripts also have access to a series of runtime objects that are made available to it at execution time. These runtime objects provide your JScripts with access to properties and methods that you can use to work with the Windows file system.
Using the properties and methods provided by JScript's runtime objects, you'll be able to automate an assortment of tasks , including the creation, deletion, renaming, copying, and moving of Windows files and folders.
In addition, you'll be able to develop JScripts that can create report and log files. You'll also be able to open and read text files programmatically. Table 6.5 provides a list of JScript runtime objects and lists their properties and methods.
Object | Description |
---|---|
Dictionary | Stores data key, item pairs Properties: CompareMode, Count, Item, Key Methods: Add, Exists, Items, Keys, Remove, RemoveAll |
Drive | Provides the capability to access disk drive properties Properties: AvailableSpace, DriveLetter, DriveType, FileSystem, FreeSpace, IsReady, Path , RootFolder, SerialNumber, ShareName, TotalSize, VolumeName Methods: This object does not support any methods. |
Drives Collection | Provides the capability to access information about disk drives Properties: Count, Item Methods: This object does not support any methods. |
File | Provides the capability to access file properties Properties: Attributes, DateCreated, DateLastAccessed, DateLastModified, Drive, Name , ParentFolder, Path, ShortName, ShortPath, Size, Type Methods: Copy, Delete, Move, OpenAsTextStream |
Files Collection | Provides the capability to process all the files in the specified folder Properties: Count, Item Methods: This object does not support any methods. |
FileSystemObject | Provides the capability to access the Windows file system and to work with other runtime objects Properties: Drives Methods: BuildPath, CopyFile, CopyFolder, CreateFolder, CreateTextFile, DeleteFile, DeleteFolder, DriveExists, FileExists, FolderExists, GetAbsolutePathName, GetBaseName, GetDrive, GetDriveName, GetExtensionName, GetFile, GetFileName, GetFolder, GetParentFolderName, GetSpecialFolder, GetTempName, MoveFile, MoveFolder, OpenTextFile |
Folder | Provides the capability to access folder properties Properties: Attributes, DateCreated, DateLastAccessed, DateLastModified, Drive, Files, IsRootFolder, Name, ParentFolder, Path, ShortName, ShortPath, Size, SubFolders , Type Methods: Copy, Delete, Move, OpenAsTextStream |
Folders Collection | Provides the capability to process all the subfolders stored in a specified folder Properties: Count, Item Method: Add |
TextStream | Provides for sequential file access Properties: AtEndOfLine, AtEndOfStream, Column, Line Methods: Close, Read, ReadAll, ReadLine, Skip, SkipLine, Write, WriteBlankLines, WriteLine |
JScript runtime objects provide access to a large collection of properties. By accessing or modifying these properties, you can interact with the Windows file system in a variety of ways. Table 6.6 provides a complete listing of JScript runtime properties.
Property | Description |
---|---|
AtEndOfLine | Returns a value of true or false based on whether the location of the file pointer precedes the end-of-line marker. |
AtEndOfStream | Returns a value of true or false based on whether the end of the file has been reached |
Attributes | Sets or returns file and folder attributes |
AvailableSpace | Returns the amount of free space on the specified drive |
Column | Returns the current column position within a file |
CompareMode | Sets or returns the comparison mode used when comparing a Dictionary object's string keys |
Count | Returns a value representing the number of items in a collection or Dictionary object |
DateCreated | Returns the creation date and time for a specified file or folder |
DateLastAccessed | Returns the date and time that the specified file or folder was last accessed |
DateLastModified | Returns the date and time that the specified file or folder was last modified |
Drive | Returns a string representing the drive letter where the specified file or folder resides |
DriveLetter | Returns a string representing a specified drive's drive letter |
Drives | Returns a Drives collection that represents all the Drive objects found on the computer |
DriveType | Returns a string representing a specified drive's type |
Files | Returns a Files collection that represents all the File objects located inside a specified folder |
FileSystem | Returns a string representing the file system type implemented on a specified drive |
FreeSpace | Returns a value representing the amount of free space available to the user on a specified drive |
IsReady | Returns a value of true or false , depending on whether a drive is currently available |
IsRootFolder | Returns a value of true or false , depending on whether a folder is the root folder |
Item | Sets or returns an item based on the specified Dictionary object key |
Key | Specifies a Dictionary object key |
Line | Returns the current line number where the pointer is located in the TextStream file |
Name | Sets or returns a file or folder's name |
ParentFolder | Returns an object reference to a file or folder's parent folder |
Path | Returns the path for a specified file, folder, or drive |
RootFolder | Returns a Folder object representing the root folder on the specified drive |
SerialNumber | Returns the serial number for a specified disk volume |
ShareName | Returns the share name for a specified network drive |
ShortName | Returns a file or folder's 8.3 character name |
ShortPath | Returns the short path for a file or folder's 8.3 character name |
Size | Returns a value representing file or folder's size (in bytes) |
SubFolders | Returns a Folders collection made up of all the folders located inside a specified folder |
TotalSize | Returns a value representing the amount of free space (in bytes) remaining on a drive |
Type | Returns a specified file or folder's type |
VolumeName | Sets or returns the volume name for a specified drive |
JScript's runtime objects also provide access to dozens of methods. Using these methods, listed in Table 6.7, you can create JScripts that can take full control of the Windows file system.
Method | Description |
---|---|
Add() (Dictionary) | Adds key and item pairs to a Dictionary object |
Add() (Folders) | Adds a Folder to a collection |
BuildPath() | Appends a name to the end of a path |
Close() | Closes an open TextStream file |
Copy() | Copies the specified file or folder |
CopyFile() | Copies one or more specified files |
CopyFolder() | Recursively copies a folder and its contents |
CreateFolder() | Creates the specified folder |
CreateTextFile() | Creates the specified text file |
Delete() | Deletes the specified file or folder |
DeleteFile() | Deletes the specified file |
DeleteFolder() | Deletes the specified folder and its contents |
DriveExists() | Returns a value of true or false based on the existence of the specified drive |
Exists() | Returns a value of true or false based on the existence of a key in a Dictionary object |
FileExists() | Returns a value of true or false based on whether a specified file is found |
FolderExists() | Returns a value of true or false based on whether a specified folder is found |
GetAbsolutePathName() | Returns a full pathname |
GetBaseName() | Returns a file name for the specified file without its file extension |
GetDrive() | Returns a Drive object reference based on the specified path |
GetDriveName() | Returns the name of a specified drive |
GetExtensionName() | Returns a specified file's file extension |
GetFile() | Returns a File object reference |
GetFileName() | Returns the last file name or folder in a specified path |
GetFileVersion() | Returns a specified file's version number |
GetFolder() | Returns a Folder object reference for the specified path |
GetParentFolderName() | Returns the name of the parent folder |
GetSpecialFolder() | Returns the name of the specified special folder |
GetTempName() | Returns the name of a specified temporary file or folder |
Items() | Returns an array made up of the items stored in a Dictionary object |
Keys() | Returns an array made up of the keys stored in a Dictionary object |
Move() | Moves a specified file or folder |
MoveFile() | Moves one or more specified files |
MoveFolder() | Moves one or more specified folders |
OpenAsTextStream() | Opens the specified file and returns a TextStream object reference to the file |
OpenTextFile() | Opens the specified file and returns an object reference to that file |
Read() | Returns a string containing a specified number of characters from a file |
ReadAll() | Reads all the contents of a file |
ReadLine() | Reads an entire line from the specified file |
Remove() | Deletes a Dictionary object's key-item pair |
Skip() | Skips x number of character positions when reading a file |
SkipLine() | Provides the capability to skip a line when reading a file |
Write() | Writes a string to the specified file |
WriteBlankLines() | Writes x number of newline characters to the specified file |
WriteLine() | Writes an entire line of text to the specified file |
[ LiB ] |