VBScript scripting programming tutorial 2

zhaozj2021-02-12  180

VBScript scripting programming tutorial 2

By SSSA2000

7/7/2004

Let's take a look at how to use FSO to perform file operation. The core of file operation is performed in the VBS during FSO. As a hacker, no matter what language learned, the operation of the document should be as good as it is, so please study carefully.

Don't talk nonsense, first look at the FSO, which object consists of:

Drive Object: Contains information for storage devices, including hard disk, optical drive, RAM disk, network drive

DRIVES collection: Provide a list of physical and logical drives

File object: check and process file

Files Collection: Provides a list of files in a folder

Folder object: Check and process folders

Folders Collection: Provide a list of bonfolders in folder

TextStream Object: Read and write text files

Take a look at the fso method: Due to a lot, I will not write every role, if you don't understand, check it yourself for MSDN. Don't say no

BULIDPATH: Add file path information to an existing file path

CopyFile

CopyFolder

CreateFolder

CreateTextFile

Deletefile

Deletefolder

Dreveexits

FileExits

Folderexists

GetabsolutePathname: Returns an absolute path for a folder or file

GetBaseName: Returns the basic path of a file or folder

GETDRIVE: Return to a DREVE object

GetDriveName: Returns the name of a drive

getExtensionName: Return to the extension

getFile: Return to a File object

GetFileName: Returns the file name in the folder

GetFolder

getParentFoldername: Returns a folder of a folder

GetSpecialFolder: Returns the object pointer to a special folder

GetTempName: Returns a name of a randomized file or folder that can be used by CreateTextFile

Movefile

Movefolder

OpenTextFile

Ok, I see this here, I think everyone understands more than half. I may not have to say more. The script is so simple, huh, huh, or continue.

1, use FSO

Since Fso is not part of WSH, we need to build his model

For example set fs = wscript.createObject ("scripting.filesystemObject")

This creates an FSO model. It is also very simple if you want to release, set fs = nothing

2, use folders

create:

We need to check if there is existence before creating, look at the program

********************************************************************************************************************************************************TION **********

DIM FS, S

Set fs = wscript.createObject ("scripting.filesystemobject")

IF (fs.folderexists)).

S = "is available"

Else

s = "not exist"

SET foldr = fs.createfolder ("c: / temp")

END IF

Delete, copy, move

delete:

Set fs = wscript.createObject ("scripting.filesystemobject")

fs.Deletefolder ("C: / Windows")

copy:

Set fs = wscript.createObject ("scripting.filesystemObject") fs.copyfolder "c: / data" "D: / data"

Note, if this time C: / Data and D: / Data exists, it will be wrong, replication will stop, if you want to force overwrites, use fs.copyfolder "C: / Data" "D: / data", True

mobile

Set fs = wscript.createObject ("scripting.filesystemobject")

Fs.MoveFolder "C: / Data" "D: / data"

About wildcard:

We can use a homer to facilitate operation:

For example, fs.movefolder: c: / data / te * "," D: / Working "

Notice that there is no, I haven't used it in the destination path "/" that is, I don't know this:

Fs.MoveFolder: C: / Data / TE * "," D: / Working / "

If you write this, if the D: / Working directory does not exist, Windows will not automatically create this directory for us.

Another point, everyone notes that there is no Folder object that is not mentioned above, we all use the FSO to provide the way, of course, using the Folder:

Set fs = wscript.createObject ("scripting.filesystemobject")

Set f = fs.getfolder ("C: / Data")

f.delete 'delete. If there is a subdirectory, it will be deleted

F.copy "D: / Working", True 'Copy to D: / Working

f.Move: "D: / Temp" "Move to D: / Temp

Special folder

Generally, the system folder: / windows / system32, temporary folder, Windows folder

Look Now, we use the environment variable to get a Windows directory, and we will say in the back of the environment variable, if I forget, please remind me

Set fs = wscript.createObject ("scripting.filesystemobject")

SET WSHSHELL = WScript.createObject ("wscript.shell")

OSDir = WSHSHELL.EXPANDENVIRONMENTSTRINGS ("% systemroot%")

Set f = fs.getFolder (OSDir)

Wscript.echo f

Of course, there is a simple method that is to use getSpecialFolder ()

This method uses three values:

0 indicates the Windows folder, the relevant constant is WindowsFolder

1 System folder, related constants is SystemFolder

2 Temporary catalog, related constant TempoRoyalfolder

Look at the example below:

******************************************************************************************************************************* ************

Set fs = wscript.createObject ("scripting.filesystemobject")

Set wfolder = fs.getspecialfolder (0) 'Returns Windows Directory

Set wfolder = fs.getspecialfolder (1) 'Returns SYSTEM32 /

Set wfolder = fs.getspecialfolder (2) 'Returns the temporary directory 3, using the file

Use the file properties:

I didn't say the attribute of the folder, everyone can raise an array from the file properties.

The file attribute is common:

Normal 0

READONLY 1

Hideen 2

System 4

Set fs = wscript.createObject ("scripting.filesystemobject")

Set f = fs.gerfile ("d: /index.txt")

F.attributes = f.attributes 1

Here, since the file properties of D: /index.txt are not known, unpredictable results will occur. If the properties of the file are 0, then it will become 1. So it is best to inquire before changing attributes

create

You need to check if the file is existing, the method is the same before you create, the method is the same as the folder.

************************************************** *****************

Set fs = wscript.createObject ("scripting.filesystemobject")

IF fs.fileexists ("c: /asd.txt") THEN

s = "available"

Else

s = not exist

Set f = fs.createtextfile ("c: /asd.txt")

END IF

Of course, we can also use Set f = fs.createtextfile ("c: /asd.txt", true)

To enforce the existing files.

Copy mobile delete file

As with the folder, we can use the FSO to provide both FILE objects.

Set fs = wscript.createObject ("scripting.filesystemobject")

fs.copyFile "C: /ASD.txt", "D: /1/ASD.txt", True 'copy file, if there is already forced overlay

fs.movefile "C: /asd.txt", "D: /" "Mobile

fs.deletefile "C: /ASD.txt" delete

Ok, the next chapter we have to learn the read and write, the reading and writing of the document is a file system, especially in the hacker programming, today's typing may have a lot of mistakes, everyone is watching, don't know Take a look at MSDN, to improve the level, only relying on yourself, others can't help you.

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

New Post(0)