网络编程
位置:首页>> 网络编程>> Asp编程>> FileSystem对象常用的文件操作函数有哪些?(2)

FileSystem对象常用的文件操作函数有哪些?(2)

 来源:asp之家 发布时间:2009-11-01 15:11:00 

标签:fso,对象,文件,函数

7、mvdir

函数格式

mvdir( DirName, Destination )

功能描述

移动一个文件夹并返回信息

应用代码

Public Function mvdir( xVar, yVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If Sys.FolderExists( xVar ) Then
  Sys.MoveFolder xVar, root&yVar
  msg ="恭喜,目录夹已移动!"
 Else
  msg ="抱歉,没有找到您想要的目录!"
 End If
 Set Sys = Nothing
 mvdir = msg
End Function

 

8、isfile

函数格式

isfile( FileName )

功能描述

检查文件是否存在并返回信息

应用代码

Public Function isfile( xVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If Sys.FileExists( xVar ) Then
  msg = True
 Else
  msg = False
 End If
 Set Sys = Nothing
 isfile = msg
End Function


9、wfile

函数格式

wfile( FileName, OverWrite, String )

功能描述

写入串到一个文件并返回信息

应用代码

Public Function wfile( xVar, yVar, zVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If yVar Then
  Set Txt = Sys.OpenTextFile( xVar, 2 )
  Txt.Write( zVar )
  Txt.Close
  msg ="恭喜,文件创建成功并保存!"
 Else
  If Sys.FileExists( xVar ) Then
   msg ="抱歉,文件已经存在!"
  End If
 Set Sys = Nothing
 wfile = msg
End Function

 

10、rfile

函数格式

rfile( FileName )

功能描述

读取一个文件并返回信息

应用代码

Public Function rfile( xVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If Sys.FileExists( xVar ) Then
  Set Txt = Sys.OpenTextFile( xVar, 1 )
  msg = Txt.ReadAll
  Txt.Close
 Else
  msg ="抱歉,文件不存在!"
 End If
 Set Sys = Nothing
 rfile = msg
End Function

 

11、afile

函数格式

afile( FileName, String )

功能描述

添加串到一个文件并返回信息

应用代码

Public Function afile( xVar, zVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If Sys.FileExists( xVar ) Then
  Set Txt = Sys.OpenTextFile( xVar, 8 )
  Txt.Write( zVar )
  Txt.Close
   msg ="恭喜,文件添加成功并保存!"
 Else
  msg ="抱歉,文件不存在!"

 End If
 Set Sys = Nothing
 afile = msg
End Function

 

12、cpfile

函数格式

cpfile( FileName, Destination, OverWrite )

功能描述

复制一个文件并返回信息

应用代码

Public Function cpfile( xVar, yVar, zVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If Sys.FileExists( xVar ) Then
  Sys.CopyFile xVar, root&yVar, zVar

  msg ="恭喜,文件复制成功!"
 Else
  msg ="抱歉,文件复制失败!"
 End If
 Set Sys = Nothing
 cpfile = msg
End Function

 

13、mvfile

函数格式

mvfile( FileName, Destination )

功能描述

移动一个文件并返回信息

应用代码

Public Function mvfile( xVar, yVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If Sys.FileExists( xVar ) Then
  Sys.MoveFile xVar, root&yVar
    msg ="恭喜,文件移动成功!"
 Else
  msg ="抱歉,文件移动失败!"

 End If
 Set Sys = Nothing
 mvfile = msg
End Function


14、rmfile

函数格式

rmfile( FileName )

功能描述

删除一个文件并返回信息

应用代码

Public Function rmfile( xVar )
 Set Sys = Server.CreateObject("Scripting.FileSystemObject")
 If Sys.FileExists( xVar ) Then
  Sys.DeleteFile( xVar )
  msg ="恭喜,文件删除成功!"
 Else
  msg ="抱歉,文件删除失败!"
 End If
 Set Sys = Nothing
 rmfile = msg
End Function

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com