fso封装类可以用仿dos命令操作文件

<%
'----------------------------------------------------------------------
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'*******************         DOSASP类 V1.01        ************************************
'作者:九五
'网站:http://dosasp.fanhei.net 您可以从http://fanhei.net/dosasp/dosasp.rar下载到最新版本
'电子邮件:zhaoyao83@hotmail.com
'版权声明:版权所有,源代码公开,各种用途均可免费使用,但是修改后必须把修改后的文件
'发送一份给作者.并且保留作者此版权信息
'**********************************************************************
'----------------------------------------------------------------------
'----------------------------------------------------------------------
Class DosAsp

Public fso
Private Sub Class_Initialize
Set fso=Server.createobject("Scripting.FileSystemObject")
End Sub


'-----------------------------
Public Function Exists(Path) '判断文件目录是否存在
Exists=fso.FileExists(Path)
if not(Exists) then
Exists=fso.FolderExists(Path)
end if
End Function
'------------------------------
Public Function Del(FullPath) '删除文件
        Del=False
        If Exists(FullPath) then
                On error resume next
                fso.DeleteFile(FullPath)
                        if err.number=0 then
                                Del=True
                        End if
        End If
End Function
'------------------------------
Public Function Copy(SourceFile,DestinationFile)'复制文件
        Dim MyFile
        If ReportFileStatus(SourceFile) = 1 Then
            Set MyFile = fso.GetFile(SourceFile)
            MyFile.Copy (DestinationFile)
            CopyAFile = 1
        Else
            CopyAFile = -1
        End If
End Function
'------------------------------
Public Function Md(FullPath) '建立目录
        If Exists(FullPath) Then
            md = false
        Else
            fso.CreateFolder(FullPath)'此处可用set获得目录路径
            md = true
        End If
End Function
'------------------------------------
Public Function Rd(FullPath) '删除目录
        If not(Exists(FullPath)) Then
            rd = false
        Else
            fso.DeleteFolder(FullPath)
            Rd = true
        End If
End Function

'------------------------------------
Public Function Cd(Path) '切换目录
If exists(Path) then
set Cd=fso.GetFolder(Path)
End If
End Function
'----------------------------------
Public Function Ren(MyOld,MyNew) '文件目录重命名
Ren=False
Dim File
If exists(MyOld) then
if instr(MyNew,"\")>0 then
MyNew = Right(s, Len(s) - (InStrRev(MyNew, "\", -1, vbTextCompare)))
end if
on error resume next
set File=fso.GetFile(MyOld)
File.Name=MyNew
if err.number=0 then
Ren=True
end if
err.clear
End If
'```````````````````````````````````````````````
if Ren=False then
If exists(MyOld) then
if instr(MyNew,"\")>0 then
Dir2 = Right(s, Len(s) - (InStrRev(MyNew, "\", -1, vbTextCompare)))
end if
on error resume next
set mDir=Cd(MyOld)
mDir.Name=MyNew
if err.number=0 then
Ren=True
end if
End If
end if
End Function

'------------------------------------
Public    Function Dir(Path) '列目录
        Dim f, f1, fc, s,flag
        If Exists(Path)  Then
            Set f = Cd(Path)
            Set fc = f.SubFolders
                flag=0
            For Each f1 in fc
             flag=flag+1
                if flag<>1 then
                s = s & "|"
                end if
                   s = s & f1.name
            Next
                Flag=0
                set fc=f.Files
                For Each f1 in fc
                flag=flag+1
                if len(s)=0 then
                if flag<>1 then
                           s = s & "|"
                   end if
                else
                        s=s & "|"
                end if       
                   s = s & f1.name
                Next
            Dir = s
        Else
            Dir = False
        End If
    End Function
       
Public Sub MsgBox(MyStr)
        Response.write "<Script language=vbscript> MsgBox("""
        Response.write MyStr
        Response.write """)</Script>"
End Sub

Private Sub Class_Terminate       
        if isobject(fso) then
                set fso=nothing
        end if
End Sub
End Class
%>

Ex:
Set dos=new DosAsp
dos.msgbox(dos.exists(server.mappath("a")))'判断目录a是否存在,并弹出一个对话框
Set dos=nothing


只要有fso权限就可以运行
原文地址:https://www.cnblogs.com/MaxIE/p/360457.html