个人博客,存放我个人的随笔,我常用的程序源码,分享软件等。
1 Apr
<%
'******************************************************************
'* Name: 操作文件函数 *
'* Version: V1.1 *
'* Update: 03/28/2009 *
'* Author: 飘逸的风 *
'* WebSite: www.webchar.com *
'******************************************************************
'作用:检索文件夹是否存在,如果存在返回True
'参数:FolderStr 文件夹名称(相对路径)
Function ExistsFolder(FolderStr)
ExistsFolder=True
If IsNull(FolderStr) Then Exit Function
Set FSOEF=Server.CreateObject("Scripting.FileSystemObject")
EFPath=Server.MapPath(FolderStr)
If Not FSOEF.FolderExists(EFPath) Then
ExistsFolder=False
End If
End Function
'作用:创建一个文件夹
'参数:FolderStr 文件夹名称(相对路径)
Function BulidFolder(FolderStr)
On Error Resume Next
BulidFolder=True
If IsNull(FolderStr) Then Exit Function
Set FSOBF=Server.CreateObject("Scripting.FileSystemObject")
BFPath=Server.MapPath(FolderStr)
FSOBF.CreateFolder(BFPath)
If Err.Number<>0 Then
BulidFolder=False
End If
Set FSOBF=Nothing
Err.Clear
End Function
'作用:修改文件夹名称
'参数:FolderStr 文件夹名称(相对路径)
' ModifyFolderStr 被修改的文件夹名
Function ModifyFolder(FolderStr,ModifyFolderStr)
On Error Resume Next
ModifyFolder=True
If IsNull(FolderStr) Then Exit Function
Set FSOMF=Server.CreateObject("Scripting.FileSystemObject")
MFPath=Server.MapPath(FolderStr)
Set MFGet=FSOMF.GetFolder(MFPath)
MFGet.Name=ModifyFolderStr
If Err.Number<>0 Then
ModifyFolder=False
End If
Set FSOMF=Nothing
Err.Clear
End Function
'作用:复制文件夹
'参数:FolderStr 原文件夹
' ToFolderStr 目标文件夹
' OverWrite 如果文件夹存在是否覆盖 True 覆盖 False 不覆盖
Function CopyFolder(FolderStr,ToFolderStr,OverWrite)
On Error Resume Next
CopyFolder=True
If IsNull(FolderStr) Then Exit Function
Set FSOCF=Server.CreateObject("Scripting.FileSystemObject")
CFPath=Server.MapPath(FolderStr)
ToCFPath=Server.MapPath(ToFolderStr)
If OverWrite=False Then
If FSOCF.FolderExists(ToCFPath) Then
CopyFolder=False
End If
ElseIf OverWrite=True Then
FSOCF.CopyFolder CFPath,ToCFPath,True
End If
If Err.Number<>0 Then
CopyFolder=False
End If
Set FSOCF=Nothing
Err.Clear
End Function
'作用:移动文件夹
'参数:FolderStr 原文件夹
' ToFolderStr 目标文件夹
' OverWrite 如果文件夹存在是否覆盖 True 覆盖 False 不覆盖
Function MoveFolder(FolderStr,ToFolderStr,OverWrite)
On Error Resume Next
MoveFolder=True
If IsNull(FolderStr) Then Exit Function
Set FSOMF=Server.CreateObject("Scripting.FileSystemObject")
MFPath=Server.MapPath(FolderStr)
ToMFPath=Server.MapPath(ToFolderStr)
If OverWrite=False Then
If FSOMF.FolderExists(ToMFPath) Then
MoveFolder=False
End If
ElseIf OverWrite=True Then
FSOMF.MoveFolder MFPath,ToMFPath
End If
If Err.Number<>0 Then
MoveFolder=False
End If
Set FSOMF=Nothing
Err.Clear
End Function
'作用:删除文件夹
'参数:FolderStr 文件夹名称(相对路径)
Function DelFolder(FolderStr)
On Error Resume Next
DelFolder=True
If IsNull(FolderStr) Then Exit Function
Set FSODF=Server.CreateObject("Scripting.FileSystemObject")
DFPath=Server.MapPath(FolderStr)
FSODF.DeleteFolder DFPath,True
If Err.Number<>0 Then
DelFolder=False
End If
Set FSODF=Nothing
Err.Clear
End Function
'作用:检索文件是否存在
'参数:FileStr 文件名称
Function ExistsFile(FileStr)
ExistsFile=True
Set FSOEFi=Server.CreateObject("Scripting.FileSystemObject")
EFiPath=Server.MapPath(FileStr)
If Not FSOEFi.FileExists(EFiPath) Then
ExistsFile=False
End If
End Function
'作用:修改文件夹名称
'参数:FileStr 文件夹名称(相对路径)
' ModifyFileStr 被修改的文件夹名
Function ModifyFile(FileStr,ModifyFileStr)
On Error Resume Next
ModifyFile=True
If IsNull(FolderStr) Then Exit Function
Set FSOMFi=Server.CreateObject("Scripting.FileSystemObject")
MFiPath=Server.MapPath(FileStr)
Set MFiGet=FSOMFi.GetFile(MFiPath)
MFiGet.Name=ModifyFileStr
If Err.Number<>0 Then
ModifyFile=False
End If
Set FSOMF=Nothing
Err.Clear
End Function
'作用:向文件写入内容
'参数:FileStr 文件名称
' FileContent 被写入的内容
' FileOpenMode 文件打开方式 1 只读 2 可写 8 追加
' Create 如果文件不存在是否创建 True 创建 False 不创建
Function WriteFile(FileStr,FileContent,FileOpenMode,Create)
On Error Resume Next
WriteFile=True
Set FSOWFi=Server.CreateObject("Scripting.FileSystemObject")
WFiPath=Server.MapPath(FileStr)
Set FSOWFiInfo = FSOWFi.OpenTextFile(WFiPath,FileOpenMode,Create)
FSOWFiInfo.Write FileContent
If Err.Number<>0 Then
WriteFile=False
End If
End Function
'作用:读取一个文件,如果错误返回False,否则返回内容
'方法:FileStr 文件名称
Function ReadFile(FileStr)
On Error Resume Next
ReadFile=False
Set FSORFi=Server.CreateObject("Scripting.FileSystemObject")
RFiPath=Server.MapPath(FileStr)
Set FSORFiInfo = FSORFi.OpenTextFile(RFiPath,1,False)
If Err.Number=0 Then
ReadFile=FSORFiInfo.ReadAll
End If
End Function
'作用:删除文件
'参数:FileStr 文件夹称(相对路径)
Function DelFile(FileStr)
On Error Resume Next
DelFile=True
If IsNull(FileStr) Then Exit Function
Set FSODFi=Server.CreateObject("Scripting.FileSystemObject")
DFiPath=Server.MapPath(FileStr)
FSODFi.DeleteFile DFiPath,True
If Err.Number<>0 Then
DelFile=False
End If
Set FSODFi=Nothing
Err.Clear
End Function
'作用:复制文件
'参数:FolderStr 原文件
' ToFolderStr 目标文件
' OverWrite 如果文件存在是否覆盖 True 覆盖 False 不覆盖
Function CopyFile(FileStr,ToFileStr,OverWrite)
On Error Resume Next
CopyFile=True
If IsNull(FileStr) Then Exit Function
Set FSOCFi=Server.CreateObject("Scripting.FileSystemObject")
CFiPath=Server.MapPath(FileStr)
ToCFiPath=Server.MapPath(ToFileStr)
If OverWrite=False Then
If FSOCFi.FileExists(ToCFiPath) Then
CopyFile=False
End If
ElseIf OverWrite=True Then
FSOCFi.CopyFile CFiPath,ToCFiPath,True
End If
If Err.Number<>0 Then
CopyFile=False
End If
Set FSOCFi=Nothing
Err.Clear
End Function
'作用:移动文件
'参数:FileStr 原文件
' ToFileStr 目标文件
' OverWrite 如果文件存在是否覆盖 True 覆盖 False 不覆盖
Function MoveFile(FileStr,ToFileStr,OverWrite)
On Error Resume Next
MoveFile=True
If IsNull(FileStr) Then Exit Function
Set FSOMFi=Server.CreateObject("Scripting.FileSystemObject")
MFiPath=Server.MapPath(FileStr)
ToMFiPath=Server.MapPath(ToFileStr)
If OverWrite=False Then
If FSOMFi.FileExists(ToMFiPath) Then
MoveFile=False
End If
ElseIf OverWrite=True Then
FSOMFi.MoveFile MFiPath,ToMFiPath
End If
If Err.Number<>0 Then
MoveFile=False
End If
Set FSOMFi=Nothing
Err.Clear
End Function
%>
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。