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

Function WriteTxtFile(FileName,TextStr,WriteORAppendType) Const ForReading = 1, ForWriting = 2 , ForAppending = 8 Dim f, m select Case WriteORAppendType Case 1: '文件举办写操纵 Set f = fso.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 = fso.OpenTextFile(FileName, ForAppending) f.Write TextStr f.Close WriteTxtFile = 1 Else WriteTxtFile = -1 End if End select End Function

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

18.判定某目次是否存在

'Response.Write ReportFolderStatus("G:\soft\delphi\my_pro\") Function ReportFolderStatus(fldr) '//成果:判定目次是否存在 '//形参:目次 '//返回值:乐成为1,失败为-1 '// Dim msg msg = -1 If (fso.FolderExists(fldr)) Then msg = 1 Else msg = -1 End If ReportFolderStatus = msg End Function

19.显示目次建设时信息

Function ShowFolderAccessInfo(FolderName,InfoType) '//成果:显示目次建设时信息 '//形参:目次名,信息种别 '// 1 -----建设时间 '// 2 -----上次会见时间 '// 3 -----上次修改时间 '// 4 -----目次路径 '// 5 -----目次名称 '// 6 -----目次范例 '// 7 -----目次巨细 '// 8 -----父目次 '// 9 -----根目次 '//返回值:乐成为目次建设时信息,失败:-1 '// Dim f, s If ReportFolderStatus(FolderName) = 1 then Set f = fso.GetFolder(FolderName) select Case InfoType Case 1 s = f.Datecreated '// 1 -----建设时间 Case 2 s = f.DateLastAccessed '// 2 -----上次会见 时间 Case 3 s = f.DateLastModified '// 3 -----上次修改时间 Case 4 s = f.Path '// 4-----文件路径 Case 5 s = f.Name '// 5-----文件名称 Case 6 s = f.Type '// 6-----文件范例 Case 7 s = f.Size '// 7-----文件巨细 Case 8 s = f.ParentFolder '// 8 -----父目次 Case 9 s = f.RootFolder '// 9 -----根目次 End select ShowFolderAccessInfo = s ELse ShowFolderAccessInfo = -1 End if End Function

20.返回文件夹嵌套数

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

转载注明出处:https://www.heiqu.com/wsdfds.html