fso应用中的几个小函数

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
  1. <
  2. '功能:判断文件名是否合法 
  3. 'isFileName [filename] 
  4. '文件名不能包含下列任何字符之一 
  5. ' / / : * ? " < > | 
  6. Function isFileName(sFileName) 
  7. Dim sErrorStr, i 
  8. isFileName = TRUE 
  9. sErrorStr = Array("/", "/", ":", "*", "?", """", "<", ">", "|") 
  10. If Len(sFileName & "") = 0 Then isFileName = FALSE : Exit Function 
  11. For i = 0 To 8 
  12. If InStr(sFileName, sErrorStr(i)) > 0 Then 
  13. isFileName = FALSE 
  14. End If 
  15. Next 
  16. End Function 
  17. %> 
  18. -------------------------------------------------------------------------------- 
  19. <
  20. '功能:删除一个目录。除目录本身外,还将删除指定目录下的所有子目录和文件。用于删除目录树。 
  21. 'RD [Drive:]Path 
  22. '支持删除多级目录,支持相对路径和绝对路径。 
  23. '支持用“...”指定父目录的父目录。 
  24. ''需要PATH函数在下面 
  25. Function RD(ByVal sPath) 
  26. On Error Resume Next 
  27. Dim oFSO 
  28. sPath = Path(sPath) '//此处需要PATH函数 
  29. Set oFSO = Server.CreateObject("Scripting.FileSystemObject") 
  30. If oFSO.FolderExists(sPath) Then 
  31. oFSO.DeleteFolder sPath, True 
  32. RD = True 
  33. End If 
  34. Set oFSO = Nothing 
  35. If Err.Number > 0 Then 
  36. Err.Clear() 
  37. RD = False 
  38. Else 
  39. RD = True 
  40. End If 
  41. End Function 
  42. %> 
  43. -------------------------------------------------------------------------------- 
  44. <
  45. '功能:创建目录。 
  46. 'MD [Drive:]Path 
  47. '支持创建多级目录,支持相对路径和绝对路径。 
  48. '支持用“...”指定父目录的父目录。 
  49. '需要PATH函数在下面 
  50. Function MD(sPath) 
  51. On Error Resume Next 
  52. Dim aPath, iPath, i, sTmpPath 
  53. Dim oFSO 
  54. sPath = Path(sPath) '//此处需要PATH函数 
  55. Set oFSO = Server.CreateObject("Scripting.FileSystemObject") 
  56. If oFSO.FolderExists(sPath) Then MD = True : Exit Function 
  57. aPath = Split(sPath, "/") 
  58. iPath = UBound(aPath) 
  59. sTmpPath = "" 
  60. For i = 0 To iPath 
  61. sTmpPathsTmpPath = sTmpPath & aPath(i) & "/" 
  62. If Not oFSO.FolderExists(sTmpPath) Then 
  63. oFSO.CreateFolder(sTmpPath) 
  64. End If 
  65. Next 
  66. Set oFSO = Nothing 
  67. If Err.Number > 0 Then 
  68. Err.Clear() 
  69. MD = False 
  70. Else 
  71. MD = True 
  72. End If 
  73. End Function 
  74. %> 
  75. -------------------------------------------------------------------------------- 
  76. <
  77. '功能:计算目录绝对路径。 
  78. 'PATH [Drive:]Path 
  79. '支持多级目录,支持相对路径和绝对路径。 
  80. '支持用“...”指定父目录的父目录。 
  81. Function Path(ByVal sPath) 
  82. On Error Resume Next 
  83. If Len(sPath&"") = 0 Then sPath = "./" 
  84. If Right(sPath, 1) = ":" Then sPathsPath = sPath & "/" 
  85. sPath = Replace(sPath, "/", "/") 
  86. sPath = ReplaceAll(sPath, "//", "/", False) 
  87. sPath = ReplaceAll(sPath, "...", "../..", False) 
  88. If (InStr(sPath, ":") > 0) Then 
  89. sPathsPath = sPath 
  90. Else 
  91. sPath = Server.Mappath(sPath) 
  92. End If 
  93. Path = sPath 
  94. End Function 
  95. %> 
  96. -------------------------------------------------------------------------------- 
  97. <
  98. '功能:判断文件是否已存在。 
  99. 'IsFileExist(文件名) 
  100. Public Function IsFileExist(ByVal sFileName) 
  101. On Error Resume Next 
  102. Dim oFSO 
  103. sFileName = PATH(sFileName) 
  104. Set oFSO = CreateObject("Scripting.FileSystemObject") 
  105. IsFileExist = oFSO.FileExists(sFileName) 
  106. Set oFSO = Nothing 
  107. End Function 
  108. %> 
  109. -------------------------------------------------------------------------------- 
  110. <
  111. '功能:判断文件夹是否已存在。 
  112. 'IsFolderExist(文件名) 
  113. Public Function IsFolderExist(ByVal sFolderName) 
  114. On Error Resume Next 
  115. Dim oFSO 
  116. sFolderName = PATH(sFolderName) 
  117. Set oFSO = CreateObject("Scripting.FileSystemObject") 
  118. IsFolderExist = oFSO.FolderExists(sFolderName) 
  119. Set oFSO = Nothing 
  120. End Function 
  121. %> 
  122. -------------------------------------------------------------------------------- 
  123. <
  124. '功能:创建十进制文本文件。 
  125. 'CreateTextFile(文件内容,文件名) 
  126. '文件名支持相对路径和绝对路径。 
  127. '支持用“...”指定父目录的父目录。 
  128. Function CreateTextFile (ByVal sText, ByVal sFileName) 
  129. On Error Resume Next 
  130. sFileName = Path(sFileName) 
  131. Set oFSO = CreateObject("Scripting.FileSystemObject") 
  132. Set oWrite = oFSO.OpenTextFile(sFileName, 2, True) 
  133. oWrite.Write sText 
  134. oWrite.Close 
  135. Set oFSO = Nothing 
  136. Set oWrite = Nothing 
  137. If Err.Number > 0 Then 
  138. Err.Clear() 
  139. CreateTextFile = False 
  140. Else 
  141. CreateTextFile = True 
  142. End If 
  143. End Function 

http://www.corange.cn/archives/2008/10/1880.html

 

 

<script type=text/javascript> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript> </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值