PQ论坛's Archiver

idty 发表于 2009-9-27 10:17

写了个垃圾的 fso操作类(不知道能不能叫做类) 大家帮我完善一下吧


<p ><strong>125989100</strong> 发表于 2009-9-16 15:04</p>
<h3>写了个垃圾的   fso操作类(不知道能不能叫做类)   大家帮我完善一下吧</h3><%
option explicit
class myfso
  private path'路径
  private filecontent '写入内容
   
  public property let mypath(p)
  path=p
  end property
   
  public property let myfilecontent(p)
  filecontent=p
  end property
   
  '判断文件是否存在
  public function isfile
  dim fso
  isfile=false
  set fso = createobject("scripting.filesystemobject")
  if (fso.fileexists(path)) then isfile=true
  set fso=nothing
  end function
   
  '判断文件夹是否存在
  public function isfolder
  dim fso
  isfolder=false
  set fso = createobject("scripting.filesystemobject")
  if (fso.folderexists(path)) then isfolder=true
  set fso=nothing
  end function
   
  '创建文件并写入
  public function createfile
  dim fso, myfile
  set fso = createobject("scripting.filesystemobject")
  set myfile = fso.createtextfile(path,true)
  myfile.writeline(filecontent)
  myfile.close
  set myfile=nothing
  set fso=nothing
  end function
   
  '创建文件夹
  public Function CreateFolder
  Dim fso
  Set fso = createobject("scripting.filesystemobject")
  if not isfolder then fso.CreateFolder(path)
  Set fso=nothing
  end function
   
  '删除文件
  public Function DeleteFile
  Dim fso
  Set fso = CreateObject("Scripting.FileSystemObject")
  fso.DeleteFile(path)
  Set fso=nothing
  End Function
   
  '删除文件夹
  public Function DeleteFolder
  Dim fso
  Set fso = CreateObject("Scripting.FileSystemObject")
  fso.DeleteFolder(path)
  Set fso=nothing
  End Function
end class

dim fso

set fso= new myfso
fso.mypath=server.MapPath("aaa")
if fso.isfolder then
fso.DeleteFolder
end if
%>


不知道能不能叫做类 只是对函数的封装了 高手给下意见  
每个方法里都要 Set fso = CreateObject("Scripting.FileSystemObject")  
有没有什么方便的方法  

用property set 但是没成功<p ><strong>帅青蛙</strong> 发表于 2009-9-16 15:29</p>
定义一个全局的FSO对象,然后在Class_Initialize方法中赋值,这样**方法中直接就可以使用了。
[code]
Class MyClass
  private fso
  private Sub Class_Initialize
   set fso = CreateObject("Scripting.FileSystemObject")
  End Sub
  public Function IsFolderExists(path)
   IsFolderExists = fso.FolderExists(path)
  End Function
End Class
[/code]<p ><strong>125989100</strong> 发表于 2009-9-16 15:44</p>
谢谢~我发现property let 和 定义共有变量差不多 只不过property let里能做判断 对不对?<p ><strong>125989100</strong> 发表于 2009-9-16 16:32</p>
我想返回一个对象应该怎么写??比如说返回个rs(recordset)对象
用property set ??
怎么写 我 试了很久都没成功<p ><strong>帅青蛙</strong> 发表于 2009-9-16 16:49</p>
SET/LET印象中是一样的。
至于你要返回一个对象,直接定义Function就可以了,有什么问题?<p ><strong>125989100</strong> 发表于 2009-9-16 17:01</p>
class a
function murs
set rs=conn.execute("select * from [a]")
murs=rs
end function
end class
用的时候

set b= new a
set rs=b.murs

这样对吗 ??<p ><strong>帅青蛙</strong> 发表于 2009-9-16 17:03</p>
[code]
function getrs
set getrs = conn.execute(.....)
end function
[/code]<p ><strong>125989100</strong> 发表于 2009-9-16 17:19</p>
受教~~~~~~~~~ 谢谢,收获很多
  


页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.