《
结合FSO操作写的一个Class
》
尚在完善中,基本功能已具备.
也可作为初学者的教程
google_ad_client = "pub-2416224910262877"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_channel = ""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "008000";
尚在完善中,基本功能已具备.
也可作为初学者的教程
程序代码
<%
'*****************************CDS系统FSO操作类Beta1*****************************
'调用方法:SetObj=NewFSOControl
'所有路径必须为绝对路径,请采用Server.MapPath方法转换路径后再定义变量
'------FileRun---------------------------------------
'
'必选参数:
'FilePath------处理文件路径
'
'可选参数:
'FileAllowType------处理文件允许的类型,定义方法例:gif|jpg|png|txt
'FileNewDir------文件处理后保存到的目录
'FileNewName------新文件名前缀,请不要添加后缀,例:sample.txt则为sample
'CoverPr------是否覆盖已有的文件0为否1为是默认为1
'deletePr------是否删除原文件0为否1为是默认为1
'---------------------------------------------------------
'------UpDir(path)取path的父目录
'path可为文件,也可为目录
'------GetPrefixName(path)取文件名前缀
'path必须为文件,可为完整路径,也可是单独文件名
'------GetFileName(path)取文件名
'path必须为文件,可为完整路径,也可是单独文件名
'------GetExtensionName(path)取文件名后缀,不包含"."
'path必须为文件,可为完整路径,也可是单独文件名
'------FileIs(path)path是否为一文件
'如为,返回true否则返回false
'------FolderCreat(Path)
'------Folderdelete(Path,FileIF)
'------FileCopy(Path_From,Path_To,CoverIF)
'------FileMove(Path_From,Path_To,CoverIF)
'------Filedelete(Path)
'------Filerename(OldName,NewName,CoverIf)
ClassFSOControl
DimFSO
PrivateFile_Path,File_AllowType,File_NewFolder_Path,File_NewName,File_CoverIf,File_deleteIf
PublicPropertyLetFilePath(StrType)
File_Path=StrType
EndProperty
PublicPropertyLetFileAllowType(StrType)
File_AllowType=StrType
EndProperty
PublicPropertyLetFileNewDir(StrType)
File_NewFolder_Path=StrType
EndProperty
PublicPropertyLetFileNewName(StrType)
File_NewName=StrType
EndProperty
PublicPropertyLetCoverPr(LngSize)
IfisNumeric(LngSize)then
File_CoverIf=Clng(LngSize)
EndIf
EndProperty
PublicPropertyLetdeletePr(LngSize)
IfisNumeric(LngSize)then
File_deleteIf=Clng(LngSize)
EndIf
EndProperty
PrivateSubClass_Initialize()
SetFSO=createObject("Scripting.FileSystemObject")
File_Path=""
File_AllowType="gif|jpg|png|txt"
File_NewFolder_Path=""
File_NewName=""
File_CoverIf=1
File_deleteIf=0
EndSub
PrivateSubClass_Terminate()
Err.Clear
SetFSO=Nothing
EndSub
PublicFunctionUpDir(ByValD)
IfLen(D)=0then
UpDir=""
Else
UpDir=Left(D,InStrRev(D,"\")-1)
EndIf
EndFunction
PublicFunctionGetPrefixName(ByValD)
IfLen(D)=0then
GetPrefixName=""
Else
FileName=GetFileName(D)
GetPrefixName=Left(FileName,InStrRev(FileName,".")-1)
EndIf
EndFunction
PublicFunctionGetFileName(name)
FileName=Split(name,"\")
GetFileName=FileName(Ubound(FileName))
EndFunction
PublicFunctionGetExtensionName(name)
FileName=Split(name,".")
GetExtensionName=FileName(Ubound(FileName))
EndFunction
PublicFunctionFileIs(Path)
Iffso.FileExists(Path)then
FileIs=true
Else
FileIs=false
EndIf
EndFunction
PublicFunctionFileOpen(Path,NewFile,ReadAction,LineCount)
IfFileIs(Path)=Falsethen
IfNewFile<>1then
FileOpen=False
ElseIfFolderIs(UpDir(Path))=Falsethen
FileOpen=False
ExitFunction
Else
fso.OpenTextFilePath,1,True
FileOpen=""
EndIf
ExitFunction
EndIf
SetFileOption=fso.GetFile(Path)
IfFileOption.size=0then
SetFileOption=Nothing
FileOpen=""
ExitFunction
EndIf
SetFileOption=Nothing
SetFileText=fso.OpenTextFile(Path,1)
IfIsNumeric(ReadAction)then
FileOpen=FileText.Read(ReadAction)
ElseIfUcase(ReadAction)="ALL"then
FileOpen=FileText.ReadAll()
ElseIfUcase(ReadAction)="LINE"then
IfNot(IsNumeric(LineCount))orLineCount=0then
FileOpen=False
SetFileText=Nothing
ExitFunction
Else
i=0
DoWhileNotFileText.AtEndOfStream
FileOpen=FileOpen&FileText.ReadLine
i=i+1
Ifi=LineCountthenExitDo
Loop
EndIf
EndIf
SetFileText=Nothing
EndFunction
PublicFunctionFileWrite(Path,WriteStr,NewFile)
IfFolderIs(UpDir(Path))=Falsethen
FileWrite=False
ExitFunction
ElseIfFileIs(Path)=FalseandNewFile<>1then
FileWrite=False
ExitFunction
EndIf
SetFileText=fso.OpenTextFile(Path,2,True)
FileText.WriteWriteStr
SetFileText=Nothing
FileWrite=True
EndFunction
PublicFunctionFolderIs(Path)
Iffso.FolderExists(Path)then
FolderIs=true
Else
FolderIs=false
EndIf
EndFunction
PublicFunctionFolderCreat(Path)
Iffso.FolderExists(Path)then
FolderCreat="指定要创建目录已存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path)))then
FolderCreat="指定要创建的目录路径错误"
ExitFunction
EndIf
fso.createFolder(Path)
FolderCreat=True
EndFunction
PublicFunctionFolderdelete(Path,FileIF)
IfNot(fso.FolderExists(Path))then
Folderdelete="指定要删除的目录不存在"
ExitFunction
EndIf
IfFileIF=1then
SetFsoFile=Fso.GetFolder(Path)
If(FsoFile.SubFolders.count>0orFsoFile.Files.count>0)then
SetFsoFile=Nothing
Folderdelete="只要要删除的目录下含有文件或子目录,不允许删除"
ExitFunction
EndIf
SetFsoFile=Nothing
EndIf
Fso.deleteFolder(Path)
Folderdelete=True
EndFunction
PublicFunctionFileCopy(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileCopy="指定要复制的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileCopy="指定要复制到的目录不存在"
ExitFunction
EndIf
IfCoverIF=0andfso.FileExists(Path_To)then
FileCopy="指定要复制到的目录下已存在相同名称文件,不允许覆盖"
ExitFunction
EndIf
fso.CopyFilePath_From,Path_To
FileCopy=True
EndFunction
PublicFunctionFileMove(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileMove="指定要移动的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileMove="指定要移动到的目录不存在"
ExitFunction
EndIf
Iffso.FileExists(Path_To)then
IfCoverIF=0then
FileMove="指定要移动到的目录下已存在相同名称文件,不允许覆盖"
ExitFunction
Else
CallFiledelete(Path_To)
EndIf
EndIf
fso.MoveFilePath_From,Path_To
FileMove=True
EndFunction
PublicFunctionFiledelete(Path)
IfNot(fso.FileExists(Path))then
Filedelete="指定要删除的文件不存在"
ExitFunction
EndIf
Fso.deleteFilePath
Filedelete=True
EndFunction
PublicFunctionFilerename(OldName,NewName,CoverIf)
NewName=NewName&"."&GetExtensionName(OldName)
IfGetFileName(OldName)=NewNamethen
Filerename="更改前的文件与更改后的文件名称相同"
ExitFunction
ElseIfNot(fso.FileExists(OldName))then
Filerename="指定更改名称的文件不存在"
ExitFunction
ElseIffso.FileExists(UpDir(OldName)&"\"&NewName)then
IfCoverIf=0then
Filerename="目录下已存在与更改后的文件名称相同的文件,不允许覆盖"
ExitFunction
Else
CallFiledelete(UpDir(OldName)&"\"&NewName)
EndIf
EndIf
SetFsoFile=fso.GetFile(OldName)
FsoFile.Name=NewName
SetFsoFile=Nothing
Filerename=True
EndFunction
PublicFunctionFileRun()
IfFile_NewFolder_Path=""andFile_NewName=""then
FileRun="此操作执行后并未对指定文件产生变动,系统自动中止"
ExitFunction
ElseIfFile_Path=""orNot(fso.FileExists(File_Path))then
FileRun="要进行操作的文件不存在"
ExitFunction
ElseIfInstr(File_AllowType,GetExtensionName(File_Path))=0then
FileRun="要进行操作的文件被系统拒绝,允许的格式为:"&Replace(File_AllowType,"|","")
ExitFunction
EndIf
IfFile_NewFolder_Path=""then
File_NewFolder_Path=UpDir(File_Path)
ElseIfNot(fso.FolderExists(File_NewFolder_Path))then
FileRun="指定要移动到的目录不存在"
ExitFunction
EndIf
IfRight(File_NewFolder_Path,1)<>"\"thenFile_NewFolder_Path=File_NewFolder_Path&"\"
IfFile_NewName=""then
File_NewPath=File_NewFolder_Path&GetFileName(File_Path)
Else
File_NewPath=File_NewFolder_Path&File_NewName&"."&GetExtensionName(File_Path)
EndIf
IfFile_Path=File_NewPaththen
FileRun="此操作执行后并未对指定文件产生变动,系统自动中止"
ExitFunction
ElseIfUpDir(File_Path)<>UpDir(File_NewPath)then
IfFile_deleteIf=1then
CallFileMove(File_Path,File_NewPath,File_CoverIf)
Else
CallFileCopy(File_Path,File_NewPath,File_CoverIf)
EndIf
FileRun=True
Else
'IfFile_deleteIf=1then
CallFilerename(File_Path,GetPrefixName(File_NewPath),File_CoverIf)
'Else
'CallFileCopy(File_Path,File_NewPath,File_CoverIf)
'EndIf
FileRun=True
EndIf
EndFunction
EndClass
%>
'*****************************CDS系统FSO操作类Beta1*****************************
'调用方法:SetObj=NewFSOControl
'所有路径必须为绝对路径,请采用Server.MapPath方法转换路径后再定义变量
'------FileRun---------------------------------------
'
'必选参数:
'FilePath------处理文件路径
'
'可选参数:
'FileAllowType------处理文件允许的类型,定义方法例:gif|jpg|png|txt
'FileNewDir------文件处理后保存到的目录
'FileNewName------新文件名前缀,请不要添加后缀,例:sample.txt则为sample
'CoverPr------是否覆盖已有的文件0为否1为是默认为1
'deletePr------是否删除原文件0为否1为是默认为1
'---------------------------------------------------------
'------UpDir(path)取path的父目录
'path可为文件,也可为目录
'------GetPrefixName(path)取文件名前缀
'path必须为文件,可为完整路径,也可是单独文件名
'------GetFileName(path)取文件名
'path必须为文件,可为完整路径,也可是单独文件名
'------GetExtensionName(path)取文件名后缀,不包含"."
'path必须为文件,可为完整路径,也可是单独文件名
'------FileIs(path)path是否为一文件
'如为,返回true否则返回false
'------FolderCreat(Path)
'------Folderdelete(Path,FileIF)
'------FileCopy(Path_From,Path_To,CoverIF)
'------FileMove(Path_From,Path_To,CoverIF)
'------Filedelete(Path)
'------Filerename(OldName,NewName,CoverIf)
ClassFSOControl
DimFSO
PrivateFile_Path,File_AllowType,File_NewFolder_Path,File_NewName,File_CoverIf,File_deleteIf
PublicPropertyLetFilePath(StrType)
File_Path=StrType
EndProperty
PublicPropertyLetFileAllowType(StrType)
File_AllowType=StrType
EndProperty
PublicPropertyLetFileNewDir(StrType)
File_NewFolder_Path=StrType
EndProperty
PublicPropertyLetFileNewName(StrType)
File_NewName=StrType
EndProperty
PublicPropertyLetCoverPr(LngSize)
IfisNumeric(LngSize)then
File_CoverIf=Clng(LngSize)
EndIf
EndProperty
PublicPropertyLetdeletePr(LngSize)
IfisNumeric(LngSize)then
File_deleteIf=Clng(LngSize)
EndIf
EndProperty
PrivateSubClass_Initialize()
SetFSO=createObject("Scripting.FileSystemObject")
File_Path=""
File_AllowType="gif|jpg|png|txt"
File_NewFolder_Path=""
File_NewName=""
File_CoverIf=1
File_deleteIf=0
EndSub
PrivateSubClass_Terminate()
Err.Clear
SetFSO=Nothing
EndSub
PublicFunctionUpDir(ByValD)
IfLen(D)=0then
UpDir=""
Else
UpDir=Left(D,InStrRev(D,"\")-1)
EndIf
EndFunction
PublicFunctionGetPrefixName(ByValD)
IfLen(D)=0then
GetPrefixName=""
Else
FileName=GetFileName(D)
GetPrefixName=Left(FileName,InStrRev(FileName,".")-1)
EndIf
EndFunction
PublicFunctionGetFileName(name)
FileName=Split(name,"\")
GetFileName=FileName(Ubound(FileName))
EndFunction
PublicFunctionGetExtensionName(name)
FileName=Split(name,".")
GetExtensionName=FileName(Ubound(FileName))
EndFunction
PublicFunctionFileIs(Path)
Iffso.FileExists(Path)then
FileIs=true
Else
FileIs=false
EndIf
EndFunction
PublicFunctionFileOpen(Path,NewFile,ReadAction,LineCount)
IfFileIs(Path)=Falsethen
IfNewFile<>1then
FileOpen=False
ElseIfFolderIs(UpDir(Path))=Falsethen
FileOpen=False
ExitFunction
Else
fso.OpenTextFilePath,1,True
FileOpen=""
EndIf
ExitFunction
EndIf
SetFileOption=fso.GetFile(Path)
IfFileOption.size=0then
SetFileOption=Nothing
FileOpen=""
ExitFunction
EndIf
SetFileOption=Nothing
SetFileText=fso.OpenTextFile(Path,1)
IfIsNumeric(ReadAction)then
FileOpen=FileText.Read(ReadAction)
ElseIfUcase(ReadAction)="ALL"then
FileOpen=FileText.ReadAll()
ElseIfUcase(ReadAction)="LINE"then
IfNot(IsNumeric(LineCount))orLineCount=0then
FileOpen=False
SetFileText=Nothing
ExitFunction
Else
i=0
DoWhileNotFileText.AtEndOfStream
FileOpen=FileOpen&FileText.ReadLine
i=i+1
Ifi=LineCountthenExitDo
Loop
EndIf
EndIf
SetFileText=Nothing
EndFunction
PublicFunctionFileWrite(Path,WriteStr,NewFile)
IfFolderIs(UpDir(Path))=Falsethen
FileWrite=False
ExitFunction
ElseIfFileIs(Path)=FalseandNewFile<>1then
FileWrite=False
ExitFunction
EndIf
SetFileText=fso.OpenTextFile(Path,2,True)
FileText.WriteWriteStr
SetFileText=Nothing
FileWrite=True
EndFunction
PublicFunctionFolderIs(Path)
Iffso.FolderExists(Path)then
FolderIs=true
Else
FolderIs=false
EndIf
EndFunction
PublicFunctionFolderCreat(Path)
Iffso.FolderExists(Path)then
FolderCreat="指定要创建目录已存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path)))then
FolderCreat="指定要创建的目录路径错误"
ExitFunction
EndIf
fso.createFolder(Path)
FolderCreat=True
EndFunction
PublicFunctionFolderdelete(Path,FileIF)
IfNot(fso.FolderExists(Path))then
Folderdelete="指定要删除的目录不存在"
ExitFunction
EndIf
IfFileIF=1then
SetFsoFile=Fso.GetFolder(Path)
If(FsoFile.SubFolders.count>0orFsoFile.Files.count>0)then
SetFsoFile=Nothing
Folderdelete="只要要删除的目录下含有文件或子目录,不允许删除"
ExitFunction
EndIf
SetFsoFile=Nothing
EndIf
Fso.deleteFolder(Path)
Folderdelete=True
EndFunction
PublicFunctionFileCopy(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileCopy="指定要复制的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileCopy="指定要复制到的目录不存在"
ExitFunction
EndIf
IfCoverIF=0andfso.FileExists(Path_To)then
FileCopy="指定要复制到的目录下已存在相同名称文件,不允许覆盖"
ExitFunction
EndIf
fso.CopyFilePath_From,Path_To
FileCopy=True
EndFunction
PublicFunctionFileMove(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileMove="指定要移动的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileMove="指定要移动到的目录不存在"
ExitFunction
EndIf
Iffso.FileExists(Path_To)then
IfCoverIF=0then
FileMove="指定要移动到的目录下已存在相同名称文件,不允许覆盖"
ExitFunction
Else
CallFiledelete(Path_To)
EndIf
EndIf
fso.MoveFilePath_From,Path_To
FileMove=True
EndFunction
PublicFunctionFiledelete(Path)
IfNot(fso.FileExists(Path))then
Filedelete="指定要删除的文件不存在"
ExitFunction
EndIf
Fso.deleteFilePath
Filedelete=True
EndFunction
PublicFunctionFilerename(OldName,NewName,CoverIf)
NewName=NewName&"."&GetExtensionName(OldName)
IfGetFileName(OldName)=NewNamethen
Filerename="更改前的文件与更改后的文件名称相同"
ExitFunction
ElseIfNot(fso.FileExists(OldName))then
Filerename="指定更改名称的文件不存在"
ExitFunction
ElseIffso.FileExists(UpDir(OldName)&"\"&NewName)then
IfCoverIf=0then
Filerename="目录下已存在与更改后的文件名称相同的文件,不允许覆盖"
ExitFunction
Else
CallFiledelete(UpDir(OldName)&"\"&NewName)
EndIf
EndIf
SetFsoFile=fso.GetFile(OldName)
FsoFile.Name=NewName
SetFsoFile=Nothing
Filerename=True
EndFunction
PublicFunctionFileRun()
IfFile_NewFolder_Path=""andFile_NewName=""then
FileRun="此操作执行后并未对指定文件产生变动,系统自动中止"
ExitFunction
ElseIfFile_Path=""orNot(fso.FileExists(File_Path))then
FileRun="要进行操作的文件不存在"
ExitFunction
ElseIfInstr(File_AllowType,GetExtensionName(File_Path))=0then
FileRun="要进行操作的文件被系统拒绝,允许的格式为:"&Replace(File_AllowType,"|","")
ExitFunction
EndIf
IfFile_NewFolder_Path=""then
File_NewFolder_Path=UpDir(File_Path)
ElseIfNot(fso.FolderExists(File_NewFolder_Path))then
FileRun="指定要移动到的目录不存在"
ExitFunction
EndIf
IfRight(File_NewFolder_Path,1)<>"\"thenFile_NewFolder_Path=File_NewFolder_Path&"\"
IfFile_NewName=""then
File_NewPath=File_NewFolder_Path&GetFileName(File_Path)
Else
File_NewPath=File_NewFolder_Path&File_NewName&"."&GetExtensionName(File_Path)
EndIf
IfFile_Path=File_NewPaththen
FileRun="此操作执行后并未对指定文件产生变动,系统自动中止"
ExitFunction
ElseIfUpDir(File_Path)<>UpDir(File_NewPath)then
IfFile_deleteIf=1then
CallFileMove(File_Path,File_NewPath,File_CoverIf)
Else
CallFileCopy(File_Path,File_NewPath,File_CoverIf)
EndIf
FileRun=True
Else
'IfFile_deleteIf=1then
CallFilerename(File_Path,GetPrefixName(File_NewPath),File_CoverIf)
'Else
'CallFileCopy(File_Path,File_NewPath,File_CoverIf)
'EndIf
FileRun=True
EndIf
EndFunction
EndClass
%>
转自
落伍者
原作者:tonycc
google_ad_client = "pub-2416224910262877"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_channel = ""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "008000";