WaBis

walter.bislins.ch

Datei: fsdir.inc

Inhalt der Datei: ./asp/fs/fsdir.inc
<%
' fsdir.inc: (C) http://walter.bislins.ch/doku/fs
'
' Some File-System Functions, optimized for speed
' - uses a common FileSystemObject for all operations
' - all paths may be relative to the application or absolute
' - supports both unix and DOS style path delimeter
' - exports global object FSDir to access file system functions
'
' Dependencies:
' - fs.inc

class CFsDirInfos
  ' class for fast queries of directories
  private mAbsPath
  private mFolder
  private mFiles

  private sub Class_Initialize
    mAbsPath = ""
    set mFolder = Nothing
    set mFiles = Nothing
  end sub

  sub Init( aRelPath )
    if FS.FolderExists(aRelPath) then
      mAbsPath = FS.MapPath(aRelPath)
      set mFolder = FS.GetFolder(aRelPath)
      set mFiles = mFolder.Files
    end if
  end sub

  public property Get AbsPath
    AbsPath = mAbsPath
  end property

  public property Get Folder
    set Folder = mFolder
  end property

  public property Get Files
    set Files = mFiles
  end property

  function FileExists( aFilename )
    dim fileObj
    set fileObj = GetFile( aFilename )
    if fileObj is Nothing then
      FileExists = false
    else
      FileExists = true
    end if
  end function

  function GetFile( aFilename )
    dim fileObj
    on error resume next
    set GetFile = Nothing
    if mFiles is Nothing then exit function
    ' Note: ohne Klammern funktioniert mFiles.Item() nicht!???
    set fileObj = mFiles.Item((aFilename))
    if Err <> 0 then
      Err.Clear
    else
      set GetFile = fileObj
    end if
  end function

end class

class CFileSystemDirectories
  private mDirs
  private mLastPath    ' cache
  private mLastDirInfo ' cache

  private sub Class_Initialize
    set mDirs = Server.CreateObject("Scripting.Dictionary")
    mDirs.CompareMode = 0
    mLastPath = ""
    set mLastDirInfo = Nothing
  end sub

  function GetDirInfos( aPath )
    dim dir, absPath
    if aPath = mLastPath then
      set GetDirInfos = mLastDirInfo
      exit function
    end if
    absPath = FS.MapPath(aPath)
    if not mDirs.Exists(absPath) then
      set dir = new CFsDirInfos
      dir.Init aPath
      mDirs.Add absPath, dir
    else
      set dir = mDirs.Item( absPath )
    end if
    mLastPath = aPath
    set mLastDirInfo = dir
    set GetDirInfos = dir
  end function

  function GetFile( aPath )
    dim path, filename, dir
    FS.SplitPath aPath, path, filename
    set dir = GetDirInfos(path)
    if dir is Nothing then
      set GetFile = Nothing
    else
      set GetFile = dir.GetFile(filename)
    end if
  end function

  function FileExists( aPath )
    dim path, filename, dir
    on error resume next
    FS.SplitPath aPath, path, filename
    set dir = GetDirInfos(path)
    if Err <> 0 then
      Err.Clear
      FileExists = false
    elseif dir is Nothing then
      FileExists = false
    else
      FileExists = dir.FileExists(filename)
    end if
  end function

  function DateLastModified( aPath )
    ' require FileExists(aPath)
    dim file
    set file = GetFile(aPath)
    DateLastModified = file.DateLastModified
  end function

end class

dim FSDir
set FSDir = new CFileSystemDirectories

%>

Weitere Infos zur Seite
Erzeugt Dienstag, 18. Oktober 2011
von wabis
Zum Seitenanfang
Geändert Freitag, 13. April 2012
von *System*