Tutorials to .com

Tutorials to .com » Asp » Base » Advanced Programming ASP 3.0 (20)

Advanced Programming ASP 3.0 (20)

Print View , by: iSee ,Total views: 15 ,Word Count: 2853 ,Date: Sun, 26 Apr 2009 Time: 12:18 AM

Summary 5.4.1 FileSystemObject object members
FileSystemObject object to provide a series of attributes and methods that can be used to manipulate them to some of the FileSystemObject object to achieve the target slave. Here is a summary of all the content, and then introduced each of the target slave.
1. Attributes FileSystemObject
FileSystemObject object that there is only one attribute, it used to be the current machine drive all the valid list, such as shown in Table 5-4:
Table 5-4 FileSystemObject object's properties and description
Properties
Description

Drivers
Return to the local computer the list of available drives.

2. FileSystemObject method
FileSystemObject provide subordinate object using a series of methods, including subordinate Drive, Folder and File objects and so on. It also achieved for the two methods TextStream object: CreateTextFile and OpenTextFile. Used in accordance with the type of object will be divided into three types of methods.
(1) drive on the way
And driver-related methods, such as shown in Table 5-5:
Table 5-5 with the drive and note the
Methods
Description

DriveExists (drivespec)
If the specified drivespec drives exist, return True, otherwise return False. drivespec parameters can be a drive letter, or files, folders, complete absolute path

GetDrive (drivespec)
Drivespec to return to the designated drive of the Drive object corresponding to. drivespec may contain a colon, the path separator or a network share, that is to say: "C", "C:", "C: \" and "\ \ machine \ sharename"

GetDriveName (drivespec)
Drivespec designated by the string to return the name of the drive. drivespec parameter must be a file or folder's absolute path, or simply drive letters, such as: "c:" or "c"

(2) the method of the folder
And the method of the folder as shown in Table 5-6:
Table 5-6 and the relevant folder and note
Methods
Description

BuildPath (path, name)
The existing path on the path to add the name for the name of the file or folder, if necessary, then add the path separator '\'

CopyFolder (source, destination, overwrite)
From the specified source folder source (can contain wildcards) to copy one or more folders to the destination folder specified destination, the source file that contains all the files in the folder. If source contains wildcards or destination at the end of the path separator ( '\'), so that the destination is to place copies of the source folder of the folder. Otherwise, that destination is to create a new folder of the path name. If the destination folder already exists and overwrite parameter is set to False, will result in error, overwrite the default parameter is True

CreateFolder (foldername)
Path to create a folder called foldername. If the foldername that already exist will result in errors

DeleteFolder (folderspec, force)
Delete folderspec designated by one or more folders (can be included in the last part of the path through the distribution site) and all folder contents. Force if the optional parameter is set to true, then even if the folder contains a document with read-only attribute, will also delete the folder. Force the default parameter is False

FolderExist (folderspec)
If the specified folder folderspec existence return True, otherwise return False. parameters folderspec folder can contain absolute or relative path, or simply to see the current folder in the folder name

GetAbsolutePathName (pathspec)
Return to the specified folder path, taking into account the current folder path. For example, if the current folder is "c: \ docs \ sales \", and pathspec is "jan", to return to the character is "c: \ docs \ sales \ jan". Wildcard ,".." and "\ \" path operator can be accepted

GetFolder (folderspec)
Return to the specified folder folderspec corresponding Folder object. folderspec folder can be relative or absolute path

GetParentFolderName (pathspec)
Pathspec return the file or folder on a folder. Not test the existence of the folder

GetSpecialfolder (folderspec)
Return to a specific Windows folder that corresponds to the Folder object. Parameter value is folderspec permission WindowsFolder (0), SystemFolder (1) and TemporaryFolder (2)

MoveFolder (source, destination)
Source designated to one or more folders to the specified destination folder. Source can be included in a wildcard, but not of the destination. If source contains wildcards or destination at the end of the path separator ( '\'), that is to place the source destination folder, otherwise it is a new folder and name the full path. If the purpose of destination folder already exists then an error

(3) methods and documents
And documents relating to the methods shown in Table 5-7:
Methods
Description

CopyFile (source, destination,
overwrite)
The source (can contain wildcards) specified one or more files are copied to the destination folder specified destination. If source contains wildcards or destination at the end of the path separator ( '\'), then that is the destination folder. Otherwise, the view that a new destination for the complete path and file name. If the target folder already exists and overwrite parameter is set to False, will produce an error. Overwrite the default parameter is True

CreateTextFile (filename, overwrite,
unicode)
File name with the specified filename in the disk to create a new text file, and return TextStream corresponding object, if the optional overwrite parameter is set to True, the path is covered under the same document have the same name. Overwrite the default parameter is False. If unicode optional parameters set to True, the contents of the file will be stored as Unicode text, unicode default parameter is False

DeleFile (filespec, force)
Delete filespec specified by one or more documents (in the last part of the path contains a wildcard). Force if the optional parameter is set to true, then also delete the file with read-only attribute. Force the default parameter is False

FileExists (filespec)
If the specified file filespec exists True, otherwise return False. filespec parameter file can contain an absolute path or relative path, or the current folder in the file name

GetBaseName (filespec)
Return filespec specified the name of the file that contains the file path to remove the files but the extension

GetExtensionName (filespec)
The return of the documents specified filespec extension

GetFile (filespec)
The return of the documents specified by filespec corresponding File object. Document can specify the relative or absolute path

GetFileName (pathspec)
Pathspec to return to the specified file path or file name, file name if there is no return to the last folder name. Does not check the file or folder exists

GetTempName ()
Returns a randomly generated file name, for the completion of the necessary computing temporary file or folder

MoveFile (source, destination)
Source designated to one or more source files to destination folder specified purpose. Source can be included in a wildcard, but not destination. If the source contains at or through the allocation at the end destination is the path separator ( '\'), so that the destination is a folder. Otherwise, that is a new destination folder and name the full path. The purpose of the folder if it already exists error

OpenTextFile (filename, iomode, create,
format)
Create a file name is the filename, or open an existing document, called the filename, and returns an object associated with TextStream. filename parameter can contain absolute or relative path. iomode parameter specifies the requested access type. Allowed values are ForReading (1) (default), ForWriting (2), ForAppending (8). When writing or appending to a file does not exist, if the create parameter set to true, will create a new document. Create default parameter is False. Description of the document format parameters to read or write data formats. Allowed values are: TristatetFalse (0) (default), in accordance with the open ASCII format; TristatetTrue (-1), in accordance with the Unicode format to open; TristateDefault (-2), the default format of open systems

Unicode file using the two bytes for each character marking the abolition of ASCII characters up to 256 constraints.

5.4.2 the use of drive
FileSystemObject object is to use the following simple example, it uses methods DriveExists existing list of drive letters:
'In vbscript
Set objFSO = Server.CreateObject ( "Scripting.FileSystemObject")
For intCode = 65 To 90 'ANSI codes for' A 'to' Z '
strLetter = Chr (intCode)
If objFSO.DriveExists (strLetter) Then
Response.Write "Found drive" & strLetter & ": <BR>"
End If
Next
Or JScript:
/ / In jscript
var objFSO = Server.CreateObject ( 'Scripting.FileSystemObject');
for (var intCode = 65; intCode <= 90; intCode + +) (/ / ANSI codes for 'A' to 'Z'
strLetter = String.formCharCode (intCode);
If (objFSO.DriveExists (strLetter))
Response.Write ( 'Found drive' + strLetter + ": <BR>");
)
This section of the two procedures are the same results, as shown in Figure 5-9:


Figure 5-9 lists the drive
This page is driveexists_vb.asp, by the book's sample files.
1. Drive Object
As already seen, FileSystemObject object contains an attribute - Drives, it returned to a local computer drive all the available collections.
Drives set in each entry is a Drive object. Drive object's properties as shown in Table 5-8:
Table 5-8 Drive object's properties and description
Properties
Description

AvailableSpave
Taking into account the fixed account and / or other restrictions, to return to drive for the users of the space available

DriveLetter
Drive back to the letters

DriveType
Return to the type of drive. Return value can be Unknown (0), Removeable (1), Fixed (2), Network (3), CDRom (4) and RamDisk (5). However, it should be noted that the current version does not support the scrrun.dll predefined constants Network, must be used instead of 3 decimal

FileSystem
Drive to return to the type of file system. Return values, including "FAT", "NTFS" and "CDFS"

FreeSpace
Drive can be used to return the remainder of the total space

IsReady
Returns a boolean value indicates whether the drive is ready

Path
Return to a drive letter and colon path composed of drive, that is "C:"

RootFolder
Drive back to the representative of the root folder of the Folder object

SerialNumber
Return to a disk volume is used to identify the serial number of decimal

ShareName
If it is a network drive, the drive to return to the network share name

TotalSize
Return the total drive capacity (in bytes)

VolumeName
Set or return to a local drive volume name

Therefore, the collection through the use of Drives in the Drive object, the server can generate a list of drives, and by checking each possible drive letter drive to determine the existence of the methods, more efficient. We can also drive on the information. In VBScript, the code is as follows:
'In VBScript:
'Create a FileSystemObject instance
Set objFSO = Server.CreateObject ( "Scripting.FileSystemObject")
'Create a Drives collection
Set colDrives = objFSO.Drives
'Iterate through the Drives collection
For Each objDrive in colDrives

Response.Write "DriveLetter: <B>" & objDrive.DriveLetter & "</ B>"
Response.Write "DriveType: <B>" & objDrive.DriveType
Select Case objDrive.DriveType
Case 0: Response.Write "- (Unknown)"
Case 1: Response.Write "- (Removable)"
Case 2: Response.Write "- (Fixed)"
Case 3: Response.Write "- (Network)"
Case 4: Response.Write "- (CDRom)"
Case 5: Response.Write "- (RamDisk)"
End Select
Response.Write "</ B>"

If objDrive.DriveType = 3 Then
If objDrive.IsReady Then
Response.Write "Remote drive with ShareName: <B>" & objDrive.ShareName & "</ B>"
Else
Response.Write "Remote drive - <B> IsReady </ B> property returned_
<B> False </ B> <BR> "
End If
Else If objDrive.IsReady then
Response.Write "FileSystem: <B>" & objDrive.FileSystem & "</ B>"
Response.Write "SerialNumber: <B>" & objDrive.SerialNumber & "</ B> <BR>"
Response.Write "Local drive with VolumeName: <B>" & _
objDrive.VolumeName & "</ B> <BR>"
Response.Write "AvailableSpace: <B>" & FormatNumber (_
objDrive.AvailableSpace / 1024, 0) & "</ B> KB"
Response.Write "FreeSpace: <B>" & FormatNumber (_
objDrive.FreeSpace / 1024, 0) & "</ B> KB"
Response.Write "TotalSize: <B>" & FormatNumber (_
objDrive.TotalSize / 1024, 0) & "</ B> KB"
End if
Response.Write "<P>"
End if
Next
Note that can not be compared predefined constants Network drives DriveType property, because (at least in the current version of scrrun.dll) in the type library constants omitted Network, it is no longer used as a public constant.
In JScript, the procedure is:
/ / In JScript:
/ / Create a FileSystemObject instance
var objFSO = Server.CreateObject ( 'Scripting.FileSystemObject');
/ / Create a Drives collection
var colDrives = new Enumerator (objFSO.Drives);

for (;! colDrives.atEnd (); colDrives.moveNext ()) (
objDrive = colDrives.item ();
Response.Write ( 'DriveLetter:' + objDrive.DriveLetter + '<BR>');
Response.Write ( 'DriveType:' + objDrive.DriveType + '<BR>');

if (objDrive.DriveType == 3)
if (objDrive.IsReady)
Response.Write ( 'Remote drive with ShareName:' +
objDrive.ShareName + '<BR>')
else
Response.Write ( 'Remote drive - IsReady property returned False <BR> <BR>');
else if (objDrive.IsReady) (
Response.Write ( 'Local drive with VolumeName:' +
objDrive.VolumeName + '<BR>');
Response.Write ( 'FileSystem:' + objDrive.FileSystem + '<BR>');
Response.Write ( 'SerialNumber:' + objDrive.SerialNumber + '<BR>');
Response.Write ( 'AvailableSpace:' + objDrive.AvailableSpace + 'bytes <BR>');
Response.Write ( 'FreeSpace:' + objDrive.FreeSpace + 'bytes <BR>');
Response.Write ( 'TotalSize:' + objDrive.TotalSize + 'bytes <P>');
)
)
In the system before running this procedure It should be noted. A If there is no disk drive or CD-ROM drives do not have CD-ROM, will be an error: "Disk Not Ready". DriveLetter In addition to DriveType attributes and attributes, in the use of other properties and methods, through a check of each drive IsReady properties, can protect the page.
When running on the server for more than VBScript code, the results shown in Figure 5-10. This page is drivescollection_vb.asp, from the book provided sample file.


Figure 5-10 a detailed list of drives
2. File System location
Several methods of FileSystemObject can be used by other object references, it can be in the server's file system and any network drive location. In fact, in the asp code to use all the objects or components, in addition to ActiveX Data Object Components, FileSystemObject object is likely to be one of the most complex.
This complexity is due to the file system on how to access different parts, requires very high flexibility. For example, down from the FileSystemObject object through the use of a variety of subordinate positioning a file. Drives the process is a collection from the beginning to a Drive object, and then drive the root Folder object, and then to the sub-Folder object and then set Files folder, and finally to set the File object.
In addition, if known to access the drive, folder, or file. Can be used directly GetDrive, GetFolder, GetSpecialFolder and GetFile method. Figure 5-11 File System all contribute to an understanding of location-related components, objects, methods, and the relationship between attributes.

Figure 5-11 the relationship between the file system location


Asp Base Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.