热门文章
 
fso操作文件 实例函数
利用FSO取得BMP,JPG
FileSystemObje
fso使用:drive 读取
fso:folder 文件系
fso:file 文件对象
scripting.Text
ASP实现结构化列举并查看某
Adodb.Stream
ASP 批量文件改名
 推荐文章
 
asp无组件读取图片文件信息
限制(禁用)FSO组件的方法
fso使用例子:创建文件夹
fso:file 文件对象
fso应用中的几个小函数
ASP FSO相关的一些例子
fso的一些特殊功能
FSO读取网站系统使用空间的
使用FSO修改文件夹的名称
fso复制文件夹所有内容和删
FSO操作文件系统代码
稻香老农的无组件上传类(完整
一个基于Jscript和fs
无惧 无组件上传完整代码
asp静态模版技术之标签参数
无组件上传文件被杀毒软件误报
 
你现在的位置:您现在的位置是: 中国ASP>>ASP教程>>fso组件
fso应用中的几个小函数

<%
"功能:判断文件名是否合法
"isFileName [filename]
"文件名不能包含下列任何字符之一
" \ / : * ? " < > |
Function isFileName(sFileName)
Dim sErrorStr, i
isFileName = TRUE
sErrorStr = Array("\", "/", ":", "*", "?", """", "<", ">", "|")
If Len(sFileName & "") = 0 Then isFileName = FALSE : Exit Function
For i = 0 To 8
If InStr(sFileName, sErrorStr(i)) > 0 Then
isFileName = FALSE
End If
Next
End Function
%>

 

/>

 

<%
"功能:删除一个目录。除目录本身外,还将删除指定目录下的所有子目录和文件。用于删除目录树。
"RD [Drive:]Path
"支持删除多级目录,支持相对路径和绝对路径。
"支持用“...”指定父目录的父目录。
""需要PATH函数在下面
Function RD(ByVal sPath)
On Error Resume Next
Dim oFSO
sPath = Path(sPath) "//此处需要PATH函数
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(sPath) Then
oFSO.DeleteFolder sPath, True
RD = True
End If
Set oFSO = Nothing
If Err.Number > 0 Then
Err.Clear()
RD = False
Else
RD = True
End If
End Function
%>

 

/>

 

<%
"功能:创建目录。
"MD [Drive:]Path
"支持创建多级目录,支持相对路径和绝对路径。
"支持用“...”指定父目录的父目录。

"需要PATH函数在下面

Function MD(sPath)
On Error Resume Next
Dim aPath, iPath, i, sTmpPath
Dim oFSO
sPath = Path(sPath) "//此处需要PATH函数
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(sPath) Then MD = True : Exit Function
aPath = Split(sPath, "\")
iPath = UBound(aPath)
sTmpPath = ""
For i = 0 To iPath
sTmpPath = sTmpPath & aPath(i) & "\"
If Not oFSO.FolderExists(sTmpPath) Then
oFSO.CreateFolder(sTmpPath)
End If
Next
Set oFSO = Nothing
If Err.Number > 0 Then
Err.Clear()
MD = False
Else
MD = True
End If
End Function
%>

 

/>

 

<%
"功能:计算目录绝对路径。
"PATH [Drive:]Path
"支持多级目录,支持相对路径和绝对路径。
"支持用“...”指定父目录的父目录。


Function Path(ByVal sPath)
On Error Resume Next
If Len(sPath&"") = 0 Then sPath = "./"
If Right(sPath, 1) = ":" Then sPath = sPath & "\"
sPath = Replace(sPath, "/", "\")
sPath = ReplaceAll(sPath, "\\", "\", False)
sPath = ReplaceAll(sPath, "...", "..\..", False)
If (InStr(sPath, ":") > 0) Then
sPath = sPath
Else
sPath = Server.Mappath(sPath)
End If
Path = sPath
End Function
%>

/>

<%
"功能:判断文件是否已存在。
"IsFileExist(文件名)


Public Function IsFileExist(ByVal sFileName)
On Error Resume Next
Dim oFSO
sFileName = PATH(sFileName)
Set oFSO = CreateObject("Scripting.FileSystemObject")
IsFileExist = oFSO.FileExists(sFileName)
Set oFSO = Nothing
End Function
%>

/>

<%
"功能:判断文件夹是否已存在。
"IsFolderExist(文件名)

Public Function IsFolderExist(ByVal sFolderName)
On Error Resume Next
Dim oFSO
sFolderName = PATH(sFolderName)
Set oFSO = CreateObject("Scripting.FileSystemObject")
IsFolderExist = oFSO.FolderExists(sFolderName)
Set oFSO = Nothing
End Function
%>

/>

<%
"功能:创建十进制文本文件。
"CreateTextFile(文件内容,文件名)
"文件名支持相对路径和绝对路径。
"支持用“...”指定父目录的父目录。

Function CreateTextFile (ByVal sText, ByVal sFileName)
On Error Resume Next
sFileName = Path(sFileName)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWrite = oFSO.OpenTextFile(sFileName, 2, True)
oWrite.Write sText
oWrite.Close
Set oFSO = Nothing
Set oWrite = Nothing
If Err.Number > 0 Then
Err.Clear()
CreateTextFile = False
Else
CreateTextFile = True
End If
End Function
%>

相关信息:

fso操作文件 实例函数
利用FSO取得BMP,JPG,PNG,GIF文件信息
FileSystemObject对象成员概要
fso使用:drive 读取驱动器信息
fso:folder 文件系统
fso:file 文件对象
scripting.TextStream对象-fso读写文本
ASP实现结构化列举并查看某路径下所有文件

 

中国ASP技术 ASP.ORG.CN 版权所有 2004-2008