vb directly reads and writes file server files, read and write files (vb) (Read and write file (VB)).doc

Read and write file (VB)).doc

Read and write file (vb) (Read and write file (VB)) FSO - FileSystemObject or scripting.filesystemobject abbreviation, built-in component for IIS, used to manipulate disks, folders or text files. There are many objects, methods and properties of FSO. Here we use examples to list the commonly used ones. If you want to view more detailed information, please click here to download the FileSystemObject reference. Note: "VBScript Language Reference" or "JScript Language Reference" In: "FileSystemObject User's Guide" and "Script Runtime Library Reference" are the complete references for FileSystemObject given by Microsoft.

FSO cannot manipulate binary files, to manipulate binary files, use: adodb.stream.

Create a file

Fuzzy FSO

Set FSO=Server. CreateObject("Script.FileSystemObject")

Set F = FSO. CreateTextFile("C:\test.txt", the real second parameter indicates whether to overwrite the target file if it exists)

write("write content")

f.writeline("write content and wrap")

f.writeblanklines(3) writes three blank lines (equivalent to pressing Enter three times in a text editor)

F.()

set f=none

Set up FSO

Open and read the file

Fuzzy FSO

Set FSO=Server. CreateObject("Script.FileSystemObject")

Set F = FSO. The second parameter 1 in go("C:\test.txt", 1, false) means read-only open, and the third parameter means whether to create the target file when it does not exist

(3) "Move the current position back three characters f.skip

F. skipline()" will move the current position to the first character of the next line, note: no parameters

response. Write f.read(3) to read three characters back from the current position and move the current position back three characters

response. Write F. readline()" to read backwards from the current position until a newline character is encountered (do not read a newline character), and move the current position to the first character of the next line, note: no parameters

响应。写F. readall()”从当前位置向后读取,直到文件结束,并将当前位置移动到文件的最后

如果f.atendofline然后

响应。写(“一行的结尾!”)

最后如果

如果f.atendofstream然后

响应。写(“文件的结尾!”)

最后如果

F.()

设置f =无

设置FSO

打开并写文件

模糊FSO

设置FSO =服务器。CreateObject(“脚本。FileSystemObject”)

集F = FSO。中去(“C:\测试。txt”,2、假)的第二个参数2表示重写,如果是8表示追加

写(“写入内容”)

f.writeline(“写入内容并换行”)

f.writeblanklines(3)的写入三个空白行(相当于在文本编辑器中按三次??车)

F.()

设置f =无

设置FSO

判断文件是否存在

暗淡的光

设置FSO =服务器。CreateObject(“脚本。FileSystemObject”)

如果FSO。存在(“C:\测试.txt”)然后

响应。写(“目标文件存在”)

其他的

响应。写(“目标文件不存在”)

最后如果

设置FSO

移动文件

暗淡的光

设置FSO =服务器。CreateObject(“脚本。FileSystemObject”)

调用FSO。MoveFile(“C:\测试.txt”、“D: \ test111 .txt”)的两个参数的文件名部分可以不同

设置FSO

复制文件

暗淡的光

设置FSO =服务器。CreateObject(“脚本。FileSystemObject”)

调用FSO。CopyFile(“C:\测试.txt”、“D: \ test111。

Txt "" ". The filename of the two parameter can be different

Set FSO = nothing

Delete file

Dim FSO

Set FSO = server.CreateObject ("Scripting.FileSystemObject")

Fso.DeleteFile ("C:\test.txt")

Set FSO = nothing

create folder

Dim FSO

Set FSO = server.CreateObject ("Scripting.FileSystemObject")

Fso.CreateFolder ("C:\test")] the parent folder of the destination folder must exist

Set FSO = nothing

Determine whether the folder exists

Dim FSO

Set FSO = server.CreateOb

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324364660&siteId=291194637