精美而实用的网站,关注web编程技术、网站运营、SEO推广,让您轻松愉快的学习

以下为两个自写的ASP函数,第一个函数CheckDir,用于判断所指定的文件夹是否存在,也就是目录是否存在;第二个函数CheckFile用于检查指定文件是否存在在于某个目录中。

两个函数都是基于ASP中的FileSystemObject对象,也就是FSO,写成函数方便以后使用。

ASP检查目录是否存在的函数代码

Function CheckDir(FolderPath)
dim fso
folderpath=Server.MapPath(".")&"\"&folderpath
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(FolderPath) then
'存在
    CheckDir = True
Else
'不存在
    CheckDir = False
End if
Set fso = nothing
End Function

ASP检查文件是否存在的函数代码

Function CheckFile(FilePath) '检查某一文件是否存在
  Dim fso
  Filepath=Server.MapPath(FilePath)
  Set fso = Server.CreateObject("Scripting.FileSystemObject")
  If fso.FileExists(FilePath) then
  '存在
      CheckFile = True
  Else
  '不存在
      CheckFile = False
  End if
  Set fso = nothing
End Function
Tags:ASP 目录 FileSystemObject