ASP中常用的22个FSO文件操作函数整理(3)

11.利用FSO读取文本文件内容

Function ReadTxtFile(FileName)
Const ForReading = 1, ForWriting = 2
Dim f, m
If ReportFileStatus(FileName) = 1 then
Set f = fso.OpenTextFile(FileName, ForReading)
m = f.ReadLine
'm = f.ReadAll
'f.SkipLine
ReadTxtFile = m
f.Close
Else
ReadTxtFile = -1
End if
End Function 

12.FSO返回文件夹目录空间大小

Function GetFolderSize(FolderName)
'//功能:取目录大小
'//形参:目录名
'//返回值:成功为目录大小,失败为-1
'//
Dim f
If ReportFolderStatus(FolderName) = 1 Then
Set f = fso.GetFolder(FolderName)
GetFolderSize = f.Size
Else
GetFolderSize = -1
End if
End Function 

13.使用FSO创建文件夹

Function createFolderDemo(FolderName)
'//功能:创建的文件夹
'//形参:目录名
'//返回值:成功为1,失败为-1
'//
Dim f
If ReportFolderStatus(Folderspec) = 1 Then
createFolderDemo = -1
Else
Set f = fso.createFolder(FolderName)
createFolderDemo = 1
End if
End Function 

14.FSO删除指定文件夹目录

Function deleteAFolder(Folderspec)
'//功能:目录删除
'//形参:目录名
'//返回值:成功为1,失败为-1
'//
Response.write Folderspec
If ReportFolderStatus(Folderspec) = 1 Then
fso.deleteFolder (Folderspec)
deleteAFolder = 1
Else
deleteAFolder = -1
End if
End Function 

15.FSO显示指定目录的文件夹目录列表

Function ShowFolderList(folderspec)
'//功能:目录存在时显示此目录下的所有子目录
'//形参:目录名
'//返回值:成功为子目录列表,失败为-1
'//
Dim f, f1, fc, s
If ReportFolderStatus(folderspec) = 1 Then
Set f = fso.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 

16.FSO复制指定文件夹目录

Function CopyAFolder(SourceFolder,DestinationFolder)
'//功能:源目录存在时,才能对目录进行复制,目的目录无影响
'//形参:源目录,目的目录
'//返回值:成功为1,失败为-1
'//
Dim MyFolder
If ReportFolderStatus(SourceFolder) = 1 and ReportFolderStatus(DestinationFolder) = -1 Then
Set MyFolder = fso.GetFolder(SourceFolder)
fso.CopyFolder SourceFolder,DestinationFolder
CopyAFolder = 1
Else
CopyAFolder = -1
End if
End Function 

17.移动指定文件夹目录

Function MoveAFolder(SourcePath,DestinationPath)
'//功能:源目录存在时目的目录不存在时才能对目录进行移动
'//形参:源目录,目的目录
'//返回值:成功为1,失败为-1
'//
If ReportFolderStatus(SourcePath)=1 And ReportFolderStatus(DestinationPath)=0 Then
fso.MoveFolder SourcePath, DestinationPath
MoveAFolder = 1
Else
MoveAFolder = -1
End if
End Function 
      

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2400.html