FilesystemObject

zhaozj2021-02-11  189

Use

FileSystemObject (FSO) Object mode is programmed, then:

Use the CREATEOBJECT method to create a FileSystemObject object. Use the appropriate method on the newly created object. Access the properties of the object. FSO object mode is included in Scripting

In the type library, the library is located in the scrrun.dll file. Thus, to use the FSO object mode, Scrrun.dll must be placed in the appropriate system directory of the web server.

Create a FileSystemObject object

First, use

CREATEOBJECT object to create

FileSystemObject object, in VBScript, use the following code to create

An example of FileSystemObject:

DIM fsoset fso = creteObject ("scripting.filesystemObject")

Example code demonstrates how to create

An instance of FileSystemObject.

In JScript, use the following code to do the same thing:

VAR fso; fso = new activiXObject ("scripting.filesystemObject");

In these two examples,

Scripting is the name of the type library, and

FileSystemObject is the name of the object you want to create. You can only create

An instance of the FileSystemObject object, regardless of the number of times attempting to create another instance.

Use the appropriate method

Second, use

The appropriate method of the FileSystemObject object. For example, to create a new object, use

CreateTextFile or

CREATEFOLDER (FSO object mode does not support the creation or deletion of the drive).

To delete an object, use the DELETEFILE and DELETEFOLDER method for the FileSystemObject object, or the DELETE method for the File and Folder objects. You can also use the appropriate method to copy and move files and folders.

Note Some features in the FileSystemObject object mode are extra. For example, you can use the CopyFile method of the FILESystemObject object, or you can copy the file with the copy method of the File object. These two method functions are the same; both methods can make programming flexible.

Access existing drives, files and folders

To access existing drives, files, or folders, use

The appropriate "get" method in the FILESystemObject object:

GetDrive getFolder getFile To access existing files in VBScript:

DIM FSO, F1SET FSO = CREATEOBJECT ("scripting.filesystemObject") set f1 = fso.getfile ("c: /test.txt")

In Jscript, you want to do the same thing, use the following code:

VAR FSO, F1; FSO = New ActiveXObject ("scripting.filesystemObject"); f1 = fso.getfile ("c: //test.txt");

Don't use the "get" method for the newly created object, because the "create" function has returned a handle of that object. For example, if used

The CreateFolder method creates a new folder, do not use the getFolder method to access its properties, such as

Name,

PATH,

Size, etc. Just set a variable to

CreateFolder function to get a new creation of the handle name and access its properties, methods, and events. To do this in VBScript, use the following code:

Sub CreateFolder Dim Fso, FLDR Set Fso = CreateObject ("scripting.filesystemObject") set fldr = fso.createfolder ("c: / mytest") response.write "create" CREATED FOLDER: "& fldr.nameend Sub

Give it in JScript

The CREATEFOLDER function sets a variable, use the following syntax:

function CreateFolder () {var fso, fldr; fso = ActiveXObject ( "Scripting.FileSystemObject"); fldr = fso.CreateFolder ( "C: // MyTest"); Response.Write ( "Created folder:" fldr.Name) }

Access object's properties

Once the handle of an object is accessible, you can access its properties. For example, to get the name of a specific folder, first create an instance of the object, then get its handle with the appropriate method (in this example

GetFolder method because the folder already exists).

In VBScript, use this code to get a handle of the getFolder method:

Set fldr = fso.getfolder ("c: /")

In Jscript, you want to do the same thing, use the following code:

Var fldr = fso.getfolder ("c: //");

Now, already have

If the Handle of the Folder object can check it

Name attribute. Use the following code in VBScript:

Response.write "Folder Name is:" & fldr.name

Check in JScript

Use the following syntax:

Response.write ("Folder Name IS: FLDR.NAME);

To find out the last time to modify the file, use the following VBScript syntax:

DIM FSO, F1SET FSO = CREATEOBJECT ("scripting.filesystemObject") 'gets the file object to be queried. Set f1 = fso.getfile ("c: /detlog.txt") 'printing information. Response.write "File Last Modified:" & f1.dateLastModified

In Jscript, you want to find the same thing, use the following code:

转载请注明原文地址:https://www.9cbs.com/read-4264.html

New Post(0)