vbs 练习1


建立文件 和删除文件

Option Explicit

Dim fso


Set fso=CreateObject("Scripting.FileSystemObject")


fso.CreateFolder="C:\Users\...\Desktop\test"  '建立文件夹

fso.CreateFolder="C:\Users\...\Desktop\test.txt"  ‘建立文件


fso.DeleteFile="C:\Users\...\Desktop\test"  '删除文件夹

fso.DeleteFile="C:\Users\...\Desktop\test.txt"  ‘删除文件


=====================================================================

设置ie样式打开ie并传值

Option Explicit
dim ie,x

set x=CreateObject("wscript.shell")
Set ie =CreateObject("internetExplorer.Application")

ie.Navigate "http://baidu.com"
ie.Toolbar=0
ie.StatusBar=0
ie.Height=500
ie.Width=400
ie.Top=0
ie.Left=0
ie.Resizable=0
ie.Visible=1

do while ie.Busy
wscript.sleep 3000
loop

x.sendkeys"a771948524"
x.sendkeys"{enter}"

=====================================================================

文本读取

Option Explicit

Dim fso,oFile,a

Set fso=CreateObject("Scripting.FileSystemObject")

Set oFile =fso.OpenTextFile("d:\text.txt")

For a=1 to 3

'msgbox oFile.read(1) '每次读取一个字符

msgbox oFile.readline

next

msgbox "end"

=====================================================================

文本写入

Option Explicit

Dim fso,oFile

Const WR=2

Set fso=CreateObject("Scripting.FileSystemObject")

Set oFile =fso.OpenTextFile("d:\text.txt",WR,True)


oFile.Write "teting this file"

oFile.WriteLine  "this is line"

oFile.WriteBlankLines(5) '写五行空行

oFile.Write "teting this file1"


msgbox oFile.ReadAll

=====================================================================

文本的追加写入

Option Explicit

Dim fso,oFile

Set fso=CreateObject("Scripting.FileSystemObject")

Set oFile =fso.OpenTextFile("d:\text.txt",8) ’参数8是追加写入


oFile.Write "teting this file"

oFile.WriteLine  "this is line"

oFile.WriteBlankLines(5) '写五行空行

oFile.Write "teting this file1"


文件的分割  直接拖放

Dim fso,File,Num,Temp,Temp2,Num2,Num3,Temp3,Temp4,Num4,Num5,Temp5,outname
Set fso = CreateObject("scripting.filesystemobject")
File=WScript.Arguments(0)
Num=InputBox("请输入每份字符数:")
Set Re=fso.OpenTextFile(File,1)
Temp = Re.ReadAll
Num2=Len(Temp)
Num2=Num2/Num
Num2=Fix(Num2)
For Temp2=1 To Num2
Num3=Temp2+(Temp2-1)*(Num-1)
Temp3 = Mid(Temp,Num3,Num)
outname=fso.getfile(file).parentfolder&"\"&Temp2&".txt"
fso.CreateTextFile(outname)
fso.OpenTextFile(outname,2).Write(Temp3)
Next
Num4=Len(Temp) Mod Num
Num5=Num3+Num
Temp3=Mid(Temp,Num5,Num4)
Temp5=Temp2+1
fso.CreateTextFile(fso.getfile(file).parentfolder&"\"&Temp2&".txt")
fso.OpenTextFile(fso.getfile(file).parentfolder&"\"&Temp2&".txt",8).Write(Temp3)
MsgBox "分割完成!",64,"完成!"

你可能感兴趣的:(vbs 练习1)