日期:2014-05-17  浏览次数:20931 次

ASP文本文档(txt)相关操作代码

ASP文本文档(txt)相关操作代码
2011年04月22日
  
  'ReadLine:从文件中读取一行数据
  'Read(N):从文件中读取N个字节的数据
  'ReadAll:读取文件中的所有数据
  ========================FSO=============================
  究级FSO函数,推荐使用。
  Const ForReading = 1, ForWriting = 2 , ForAppending = 8
  Dim f, m
  select Case WriteORAppendType
  Case 1: '文件进行写操作
  Set f = objFSO.OpenTextFile(FileName, ForWriting, True)
  f.Write TextStr
  f.Close
  If ReportFileStatus(FileName) = 1 then
  WriteTxtFile = 1
  Else
  WriteTxtFile = -1
  End if
  Case 2: '文件末尾进行写操作
  If ReportFileStatus(FileName) = 1 then
  Set f = objFSO.OpenTextFile(FileName, ForAppending)
  f.Write TextStr
  f.Close
  WriteTxtFile = 1
  Else
  WriteTxtFile = -1
  End if
  End select
  End Function
  '读文本文件
  Public Function ReadTxtFile(FileName)
  Const ForReading = 1, ForWriting = 2
  Dim f, m
  If ReportFileStatus(FileName) = 1 then
  Set f = objFSO.OpenTextFile(FileName, ForReading)
  m = f.ReadLine
  ReadTxtFile = m
  f.Close
  Else
  ReadTxtFile = -1
  End if
  End Function
  '建立文本文件
  '=======目录操作========
  '取目录大小
  Public Function GetFolderSize(FolderName)
  Dim f
  If ReportFolderStatus(FolderName) = 1 Then
  Set f = objFSO.GetFolder(FolderName)
  GetFolderSize = f.Size
  Else
  GetFolderSize = -1
  End if
  End Function
  '创建的文件夹
  Public Function createFolderDemo(FolderName)
  Dim f
  If ReportFolderStatus(Folderspec) = 1 Then
  createFolderDemo = -1
  Else
  Set f = objFSO.createFolder(FolderName)
  createFolderDemo = 1
  End if
  End Function
  '目录删除
  Public Function deleteAFolder(Folderspec)
  Response.write Folderspec
  If ReportFolderStatus(Folderspec) = 1 Then
  objFSO.deleteFolder (Folderspec)
  deleteAFolder = 1
  Else
  deleteAFolder = -1
  End if
  End Function
  '显示目录列表
  Public Function ShowFolderList(FolderSpec)
  Dim f, f1, fc, s
  If ReportFolderStatus(FolderSpec) = 1 Then
  Set f = objFSO.GetFolder(FolderSpec)
  Set fc = f.SubFolders
  For Each f1 in fc
  s = s & f1.name
  s = s & "|"
  Next
  ShowFolderList = s
  Else
  ShowFolderList = -1
  End if
  End Function
  '目录复制
  Public Function CopyAFolder(SourceFolder,DestinationFolder)
  objFSO.CopyFolder SourceFolder,DestinationFolder
  CopyAFolder = 1
  CopyAFolder = -1
  End Function
  '目录进行移动
  Public Function MoveAFolder(SourcePath,DestinationPath)
  If ReportFolderStatus(SourcePath)=1 And ReportFolderStatus(DestinationPath)=0 Then
  objFSO.MoveFolder SourcePath, DestinationPath
  MoveAFolder = 1
  Else
  MoveAFolder = -1
  End if
  End Function
  '判断目录是否存在
  Public Function ReportFolderStatus(fldr)
  Dim msg
  msg = -1
  If (objFSO.FolderExists(fldr)) Then
  msg = 1
  Else
  msg = -1
  End If
  ReportFolderStatus = msg
  End Function
  '目录创建时信息
  Public Function ShowFolderAccessInfo(FolderName,InfoType)
  '//功能:显示目录创建时信息
  '//形参:目录名,信息类别
  '// 1 -----创建时间
  '// 2 -----上次访问时间
  '// 3 -----上次修改时间
  '// 4 -----目录路径
  '// 5 -----目录名称
  '// 6 -----目录类型
  '// 7 -----目录大小
  '// 8 -----父目录
  '// 9 -----根目录
  Dim f, s
  If ReportFolderStatus(FolderName) = 1 then
  Set f = objFSO.GetFolder(FolderName)
  select Case InfoType
  Case 1 s = f.Datecreated
  Case 2 s = f.DateLastAccessed
  Case 3 s = f.DateLastModified