On Error Resume Next
//下面的程序出现错误继续执行
Dim xda,ye
set xda=createobject("wscript.shell")
wscript.sleep 5000//停止5000毫秒for i =1 to 1000
wscript.sleep 20
xda.AppActivate
xda.sendKeys "^v"
xda.sendKeys i
xda.sendKeys "%s"
next
2、文件创建
On Error Resume Next
dim a
set fso =CreateObject("Scripting.FileSystemObject")for a=1 to 10
set f = fso.CreateTextFile("C:\Users\Administrator\Desktop\"&a&"test.txt", ture)//ture 有同命名文件时进行覆盖
f.write("hello vbs")
f.close()
next
3、打开并写文件
set fso =CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile("C:\test.txt",2, false)//第二个参数 2 表示重写,如果是 8 表示追加
f.Write("something")
f.Close()
4、判断文件是否存在
set fso =CreateObject("Scripting.FileSystemObject")if fso.FileExists("C:\test.txt") then
response.Write("目标文件存在")else
response.Write("目标文件不存在")
end if
set fso = nothing
5、移动文件
set fso =CreateObject("Scripting.FileSystemObject")
call fso.MoveFile("C:\test.txt","D:\test111.txt")//两个参数的文件名部分可以不同
set fso = nothing
6、复制文件
set fso = server.CreateObject("Scripting.FileSystemObject")
call fso.CopyFile("C:\test.txt","D:\test111.txt")//两个参数的文件名部分可以不同
set fso = nothing
7、删除文件
set fso =CreateObject("Scripting.FileSystemObject")
fso.DeleteFile("C:\test.txt")
set fso = nothing
8、创建文件夹
set fso =CreateObject("Scripting.FileSystemObject")
fso.CreateFolder("C:\test")//目标文件夹的父文件夹必须存在
set fso = nothing
9、判断文件夹是否存在
set fso =CreateObject("Scripting.FileSystemObject")if fso.FolderExists("C:\Windows") then
response.Write("目标文件夹存在")else
response.Write("目标文件夹不存在")
end if
set fso = nothing
10、删除文件夹
set fso =CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder("C:\test")//文件夹不必为空
set fso = nothing