“未来的世界:方向比努力重要,能力比知识重要,健康比成绩重要,生活比文凭重要,情商比智商重要! ”    ——清华大学校长留给毕业生的一段话

fso文件操作大全

上一篇 / 下一篇  2007-08-09 00:21:30

创建文件
!\@}Z?NETI0dim fso, f
G8h-yV*RDP,j(M'pkj*g0set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网R%_;WR"LB
set f = fso.CreateTextFile("C:\test.txt", true) '第二个参数表示目标文件存在时是否覆盖51Testing软件测试网%Two9Z.Um0s8m P
f.Write("写入内容")51Testing软件测试网5|^rQjO n
f.WriteLine("写入内容并换行")
n8Doc_/^m0f.WriteBlankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)51Testing软件测试网L_R$h J.S^
f.Close()
p)|?8\,xf5z,D7c:gX6T0set f = nothing51Testing软件测试网%R9S;IR*M!Q!h;` v
set fso = nothing51Testing软件测试网(H}uk7nU

e)W.N+\n @7n0打开并读文件51Testing软件测试网;V@*NqUqIj
dim fso, f
i@d \5s2I'n0set fso = server.CreateObject("scrīpting.FileSystemObject")
K%z;aU!h1O6\"| Ek;[0set f = fso.OpenTextFile("C:\test.txt", 1, false) '第二个参数 1 表示只读打开,第三个参数表示目标文件不存在时是否创建51Testing软件测试网7UR1SXew
f.Skip(3) '将当前位置向后移三个字符51Testing软件测试网Ru(lT I0r U
f.SkipLine() '将当前位置移动到下一行的第一个字符,注意:无参数
$JNP/Ax0response.Write f.Read(3) '从当前位置向后读取三个字符,并将当前位置向后移三个字符
l6l?q2D3S _-J!R0response.Write f.ReadLine() '从当前位置向后读取直到遇到换行符(不读取换行符),并将当前位置移动到下一行的第一个字符,注意:无参数
c:RaR)bl F0response.Write f.ReadAll() '从当前位置向后读取,直到文件结束,并将当前位置移动到文件的最后51Testing软件测试网9g9A O7lG%]$u?
if f.atEndOfLine then
fKTa:i(S$dy0    response.Write("一行的结尾!")
I BxB#] v0end if51Testing软件测试网1W'g\W(m&jV
if f.atEndOfStream then
c6d~6G@,xxE0    response.Write("文件的结尾!")
a+rem7~}i0end if
{(C@AW-D~1~$x0f.Close()51Testing软件测试网$qjt S*b%c ?
set f = nothing
PY%d5` j3|H0set fso = nothing51Testing软件测试网0t$V`d#[%r'B |

s"u`*W$U0w0打开并写文件51Testing软件测试网W["h["s
dim fso, f
k;F1N,}'D6L!E0set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网;~C |ppB~#k']
set f = fso.OpenTextFile("C:\test.txt", 2, false) '第二个参数 2 表示重写,如果是 8 表示追加
DC/C T0O&I'GR0f.Write("写入内容")51Testing软件测试网:C8D {{i;P:RJ
f.WriteLine("写入内容并换行")51Testing软件测试网p2kp$h;\,G\ Y
f.WriteBlankLines(3) '写入三个空白行(相当于在文本编辑器中按三次回车)
{;p'js_8g TQ0f.Close()51Testing软件测试网j(M]a'k:N
set f = nothing
/M8L)H)C!U7r7}0set fso = nothing51Testing软件测试网 _5dsv c8B7B
51Testing软件测试网zbU$n-DN%F
判断文件是否存在
W\k Ix%l7X _#Z0dim fso51Testing软件测试网,K*g{5r[
set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网Ag;|(OcbJ&zq
if fso.FileExists("C:\test.txt") then
;s8D+_7WdZ.{E0    response.Write("目标文件存在")
9]U1|J!PgvO0else51Testing软件测试网 a;j~2Y*bZP'N;q
    response.Write("目标文件不存在")51Testing软件测试网3LJZ q`(|
end if51Testing软件测试网 BL!A3sH k _
set fso = nothing
UlBm}P0
s+`L/B*]c0移动文件51Testing软件测试网"L\yu5Rt v
dim fso
8H n+u\#Bt7aj0set fso = server.CreateObject("scrīpting.FileSystemObject")
DM*W'Fh]0call fso.MoveFile("C:\test.txt", "D:\test111.txt") '两个参数的文件名部分可以不同
UQ%F`#` y g0Fk0set fso = nothing51Testing软件测试网,~z2q\j-a(R
51Testing软件测试网(~0yNuu8T6I
复制文件51Testing软件测试网3Q V Xi.p-Ax
dim fso51Testing软件测试网s0X:hV"}H,z
set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网1@ps%s(sA-J
call fso.CopyFile("C:\test.txt", "D:\test111.txt") '两个参数的文件名部分可以不同
1c"n9MF!X y1i0set fso = nothing
%zf1f)J_8n.n^051Testing软件测试网$y#q| _.{;w
删除文件
C.]E n"ho8`]%Ts0dim fso51Testing软件测试网Hgh yJ(zr
set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网;e+E|I ][ @Pe
fso.DeleteFile("C:\test.txt")
2L^I!ipL@X}#F]0set fso = nothing
)u;kCR @_g051Testing软件测试网*[fI6KKL]6M
创建文件夹51Testing软件测试网yJUF2O*ZR
dim fso51Testing软件测试网u"t/ZF3\[
set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网X"}*t P1WZbc2}8b
fso.CreateFolder("C:\test") '目标文件夹的父文件夹必须存在51Testing软件测试网lsi:?7Wi*R
set fso = nothing
*K&O AL {@051Testing软件测试网 HZC$K^%Z:DBcz
判断文件夹是否存在
G:eqO[:p:_m0dim fso51Testing软件测试网^x/_VB4N
set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网:k.u7B-_/LL
if fso.FolderExists("C:\Windows") then
4Og2\k n.hH0    response.Write("目标文件夹存在")
:t}7a]4k-s0else51Testing软件测试网1m\ b+hS(Qc3_ BA
    response.Write("目标文件夹不存在")
y0v"JV2`qn)H0end if51Testing软件测试网F-vOBFY
set fso = nothing51Testing软件测试网|y:{+Vk
51Testing软件测试网3v%x2U/jd#o ~
删除文件夹51Testing软件测试网oa8A{2[&t&ZX
dim fso
(af R2I|#SJ+Z0set fso = server.CreateObject("scrīpting.FileSystemObject")51Testing软件测试网YA;a&}M I
fso.DeleteFolder("C:\test") '文件夹不必为空51Testing软件测试网 T/a"J?_)nX |%k
set fso = nothing51Testing软件测试网3L{%p*Q@uNY$L
51Testing软件测试网(V5G X!Kd,X
====51Testing软件测试网NP%BYrJ.Y
'path为要删除目录路径51Testing软件测试网8O%` lMXkgMQ
sub delfolder(path)51Testing软件测试网N6Q"h4EY(z[&R|}
Dim WshShell, oExec51Testing软件测试网8`#_e_ e W F,C QP
Set WshShell = CreateObject("Wscrīpt.Shell")
`o9N(Nfx9[}0Set ōExec = WshShell.Exec("cmd /c del /s /q "+path)
-MWZ.J-^Bys0set ōexec = wshshell.exec("cmd /c rd /s /q "+path)
K e0?/a:Q6F0end sub
X![djd0[K0=========51Testing软件测试网 WD#{ {!x3S)SQSO
51Testing软件测试网K7?}.hg7m3|o
Dim fso, msg51Testing软件测试网,H/\3`S{Iu5A^
   Set fso = CreateObject("scrīpting.FileSystemObject")51Testing软件测试网"Y%O E+EE#l/{ }+m|/A
   If (fso.FileExists("c:\testfile.txt")) Then
/]c*Bh_4~0'update the exist the file51Testing软件测试网y#aU \ tY@'C8~a
      msg = " exists."51Testing软件测试网P/s O;A8A#[8u
   Else51Testing软件测试网'm5ODOz
'create the new file51Testing软件测试网a/q(RqYT;uJ
      msg = " doesn't exist."51Testing软件测试网_yE5}7d7X j[$b
   End If
e:wRA!r5m)Q1M fcx0msgbox msg
aZ+U1f/]8Lk051Testing软件测试网~*X2O.G c0WdbV

2HB:zi*y,Af0==========

TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-23  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 58082
  • 日志数: 103
  • 图片数: 4
  • 文件数: 2
  • 建立时间: 2007-05-20
  • 更新时间: 2010-11-23

RSS订阅

Open Toolbar