服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - ASP教程 - filesystemobject组件的用法示例

filesystemobject组件的用法示例

2019-10-31 13:37asp教程网 ASP教程

filesystemobject组件的用法示例

  1. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  2. ' CreateLyrics  
  3. ' 目的:  
  4. ' 在文件夹中创建两个文本文件。  
  5. ' 示范下面的内容  
  6. ' - FileSystemObject.CreateTextFile  
  7. ' - TextStream.WriteLine  
  8. ' - TextStream.Write  
  9. ' - TextStream.WriteBlankLines  
  10. ' - TextStream.Close  
  11. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  12.  
  13. Sub CreateLyrics(Folder)  
  14.  
  15. Dim TextStream  
  16.  
  17. Set TextStream = Folder.CreateTextFile("OctopusGarden.txt")  
  18.  
  19. TextStream.Write("Octopus' Garden ") ' 请注意,该语句不添加换行到文件中。  
  20. TextStream.WriteLine("(by Ringo Starr)")  
  21. TextStream.WriteBlankLines(1)  
  22. TextStream.WriteLine("I'd like to be under the sea in an octopus' garden in the shade,")  
  23. TextStream.WriteLine("He'd let us in, knows where we've been -- in his octopus' garden in the shade.")  
  24. TextStream.WriteBlankLines(2)  
  25.  
  26. TextStream.Close  
  27.  
  28. Set TextStream = Folder.CreateTextFile("BathroomWindow.txt")  
  29. TextStream.WriteLine("She Came In Through The Bathroom Window (by Lennon/McCartney)")  
  30. TextStream.WriteLine("")  
  31. TextStream.WriteLine("She came in through the bathroom window protected by a silver spoon")  
  32. TextStream.WriteLine("But now she sucks her thumb and wanders by the banks of her own lagoon")  
  33. TextStream.WriteBlankLines(2)  
  34. TextStream.Close  
  35.  
  36. End Sub  
  37.  
  38. ' GetLyrics  
  39. ' 目的:  
  40. ' 显示 lyrics 文件的内容。  
  41. ' 示范下面的内容  
  42. ' - FileSystemObject.OpenTextFile  
  43. ' - FileSystemObject.GetFile  
  44. ' - TextStream.ReadAll  
  45. ' - TextStream.Close  
  46. ' - File.OpenAsTextStream  
  47. ' - TextStream.AtEndOfStream  
  48. ' - TextStream.ReadLine  
  49. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  50.  
  51. Function GetLyrics(FSO)  
  52.  
  53. Dim TextStream  
  54. Dim S  
  55. Dim File  
  56.  
  57. ' 有多种方法可用来打开一个文本文件,和多种方法来从文件读取数据。  
  58. ' 这儿用了两种方法来打开文件和读取文件:  
  59.  
  60. Set TextStream = FSO.OpenTextFile(TestFilePath & "\Beatles\OctopusGarden.txt", OpenFileForReading)  
  61.  
  62. S = TextStream.ReadAll & NewLine & NewLine  
  63. TextStream.Close  
  64.  
  65. Set File = FSO.GetFile(TestFilePath & "\Beatles\BathroomWindow.txt")  
  66. Set TextStream = File.OpenAsTextStream(OpenFileForReading)  
  67. Do While Not TextStream.AtEndOfStream  
  68. S = S & TextStream.ReadLine & NewLine  
  69. Loop  
  70. TextStream.Close  
  71.  
  72. GetLyrics = S  
  73.  
  74. End Function  

延伸 · 阅读

精彩推荐