51Testing软件测试网*QVH(ozo&mU!f------------------------------------51Testing软件测试网s'E+E_@.K0uq
51Testing软件测试网`ar5Vw&m!MR6i?'creat by 席飞剑(小席老师)51Testing软件测试网.f'h?y%D!C&M
51Testing软件测试网npl#J2dy'操作文本文件,操作fso对象(文件对象操作)
O6twY/z0$U%}.BjHhRso0------------------------------------51Testing软件测试网o c+|p(i^ |'nR
axk+zE0创建文件51Testing软件测试网aMS&n5rn7R
dim fso, f
*er/iadQ8l1[,~Y0set fso = server.CreateObject("Scripting.FileSystemObject")
1O,K+MoZ]XA3?2iQ!WN0set f = fso.CreateTextFile("C:\test.txt", true) '第二个参数表示目标文件存在时是否覆盖51Testing软件测试网 o;rq(Fj6\w/U0}
f.Write("写入内容")
KO4L/Q7m5Hk1vhcw'O0f.WriteLine("写入内容并换行")51Testing软件测试网.Cn/g3[H]rV
d_
g
f.WriteBlankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)
1Vq2`K](e0f.Close()51Testing软件测试网'z$y3TTf
qP)q
set f = nothing
Q8u'v]0I| A)L-r:t0set fso = nothing51Testing软件测试网+qBa?_|5|
51Testing软件测试网5Nm-_&Qp6DV-----------------------------------------------------------51Testing软件测试网Sc nP;Lq
2N8S^:Iu@:H0打开并读文件
Iq"Vv Z4Fim0dim fso, f
^q2e5WMr#@%aP0set fso = server.CreateObject("Scripting.FileSystemObject")51Testing软件测试网t`1Z@YO%W
set f = fso.OpenTextFile("C:\test.txt", 1, false) '第二个参数 1 表示只读打开,第三个参数表示目标文件不存在时是否创建51Testing软件测试网T$xA$CY8p
N%DO.p
f.Skip(3) '将当前位置向后移三个字符
.?&e`-R+_p v0f.SkipLine() '将当前位置移动到下一行的第一个字符,注意:无参数
(g/LmT
F3r0response.Write f.Read(3) '从当前位置向后读取三个字符,并将当前位置向后移三个字符51Testing软件测试网$joD*{5z9Dr
response.Write f.ReadLine() '从当前位置向后读取直到遇到换行符(不读取换行符),并将当前位置移动到下一行的第一个字符,注意:无参数51Testing软件测试网9Tmh*YPL*Cx:\}
response.Write f.ReadAll() '从当前位置向后读取,直到文件结束,并将当前位置移动到文件的最后51Testing软件测试网rpJs`+x9D6H B#jZ
if f.atEndOfLine then51Testing软件测试网r:mmQs qz
response.Write("一行的结尾!")51Testing软件测试网1p;G)sA\\
end if51Testing软件测试网:KrG&a9S}-sj
if f.atEndOfStream then51Testing软件测试网
]iX;xT!oz-^f{
response.Write("文件的结尾!")51Testing软件测试网)b
?
C1gz I
end if
$q\lm;l&T.G*j,h7Pm6P0f.Close()51Testing软件测试网[]
fs3_!Z"\
set f = nothing51Testing软件测试网TkQ'}K$Y;_M"_BT
set fso = nothing
)a
l9S2}/w%C R"}B05T"\R5i%HU$m0-----------------------------------------------------------
/x.d!l
lA?l!T051Testing软件测试网0Gk4Y6]9m打开并写文件
{'D^ q)pgoh0dim fso, f
rWY8~@V0set fso = server.CreateObject("Scripting.FileSystemObject")51Testing软件测试网)a'Q$Wv$|O'\/z8n
set f = fso.OpenTextFile("C:\test.txt", 2, false) '第二个参数 2 表示重写,如果是 8 表示追加
6Te|jg(a)Kk0f.Write("写入内容")51Testing软件测试网;k}S6{!~i3}N_p,t!u
f.WriteLine("写入内容并换行")51Testing软件测试网Oa-\2O
ICi/In
f.WriteBlankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)51Testing软件测试网o7Z~5q'D{8^gg
f.Close()
p]y}^bO0set f = nothing
z6xLs'H
h
Tg0set fso = nothing51Testing软件测试网[)B)yX~x7gm
u
51Testing软件测试网 oEir8JY-----------------------------------------------------------51Testing软件测试网Gy{5t
@@
R0lQ$|(~6zn7f0判断文件是否存在
0q0B l6Eo9pi
Q.I0dim fso
@`(^9f1z$u0set fso = server.CreateObject("Scripting.FileSystemObject")
:x9z0}@7S,iZ#d5O2r0if fso.FileExists("C:\test.txt") then
l'?k-z9J0 response.Write("目标文件存在")51Testing软件测试网K
D5A:Vo U
else
/M(|` mL!U a0 response.Write("目标文件不存在")
^2z)]T"Z$B f0end if
J)j/m.|AV-il4s0set fso = nothing51Testing软件测试网P-u'oZI;_Z)w
51Testing软件测试网/w5jF? _ i8Zq-----------------------------------------------------------
8?H9W8X#V+i)Z4T0
L
S*H9q!rG1d)S.M%K0移动文件51Testing软件测试网tlO p)@N F.S
dim fso
2ZlJ
Pwk0set fso = server.CreateObject("Scripting.FileSystemObject")51Testing软件测试网u!|A0X6\W/O3T }_
call fso.MoveFile("C:\test.txt", "D:\test111.txt") '两个参数的文件名部分可以不同51Testing软件测试网p&C.Tr/NHC
set fso = nothing
.{!]V+c)b.g051Testing软件测试网$['q5nz\4TfE-----------------------------------------------------------51Testing软件测试网gG#r6gn?Jre
51Testing软件测试网 PWxN-x L复制文件
i,C*Y%u!X-DT0dim fso51Testing软件测试网q6FmF7O
set fso = server.CreateObject("Scripting.FileSystemObject")
C2Qfi6T(S
b'qc(T
U0call fso.CopyFile("C:\test.txt", "D:\test111.txt") '两个参数的文件名部分可以不同51Testing软件测试网R%O^)KKl(z"WUg
set fso = nothing
Zlw*Gx051Testing软件测试网&QRD&^,ClB-----------------------------------------------------------51Testing软件测试网r+g/WHx
Mynd$T0删除文件51Testing软件测试网\K)UE7Sy7K[+j,U
dim fso
t,?"jDZ)zl.m0set fso = server.CreateObject("Scripting.FileSystemObject")51Testing软件测试网8K~#ZCX2x
fso.DeleteFile("C:\test.txt")51Testing软件测试网y\rvYFWI
set fso = nothing
z-K%}9^^([IX9e[051Testing软件测试网j(]
q[t^D
M6W-----------------------------------------------------------51Testing软件测试网Ye8j$ET#rN|
51Testing软件测试网d#D"k1y
d
Gn f;BS:FK创建文件夹51Testing软件测试网Q3E9V9B?3ZF ug
dim fso51Testing软件测试网7Z;Il+{!e1We+r,B1x
set fso = server.CreateObject("Scripting.FileSystemObject")
~v'|
[Z0fso.CreateFolder("C:\test") '目标文件夹的父文件夹必须存在
3Dd(Q~.v kk9u0set fso = nothing51Testing软件测试网wu*t%\ C{
51Testing软件测试网'?2Z%L
Kf7Br-----------------------------------------------------------
SI.Gc}BxHpf0k5pan#i$[0判断文件夹是否存在51Testing软件测试网VXgJlWl.X
dim fso
!D"oFEO!uf_7\0set fso = server.CreateObject("Scripting.FileSystemObject")51Testing软件测试网BH/X3bIk:O
if fso.FolderExists("C:\Windows") then
y o5cS"V K0 response.Write("目标文件夹存在")51Testing软件测试网A'a*k3B&q
o4]x
else51Testing软件测试网 TX+P$RAJLrX!AUo
response.Write("目标文件夹不存在")51Testing软件测试网v/O$Yx$c9YD
end if51Testing软件测试网}
C@"u ud
set fso = nothing51Testing软件测试网GE"Os1efS
51Testing软件测试网#UP!?GWG-----------------------------------------------------------
_[#b
J,@2F&q:q051Testing软件测试网1YWq:U:Q/}w删除文件夹51Testing软件测试网6c$S g6D5m;b,[/c_1D3[
dim fso
u
x'kr[0set fso = server.CreateObject("Scripting.FileSystemObject")
2St+b^D0`+n"X0fso.DeleteFolder("C:\test") '文件夹不必为空51Testing软件测试网)P+[}@0w]
set fso = nothing51Testing软件测试网$@9pr.\#C$wE'[
O9[;Z"c$UC0