《
結(jié)合FSO操作寫(xiě)的一個(gè)Class
》
尚在完善中,基本功能已具備.
也可作為初學(xué)者的教程
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";
尚在完善中,基本功能已具備.
也可作為初學(xué)者的教程
程序代碼
<%
'*****************************CDS系統(tǒng)FSO操作類(lèi)Beta1*****************************
'調(diào)用方法:SetObj=NewFSOControl
'所有路徑必須為絕對(duì)路徑,請(qǐng)采用Server.MapPath方法轉(zhuǎn)換路徑后再定義變量
'------FileRun---------------------------------------
'
'必選參數(shù):
'FilePath------處理文件路徑
'
'可選參數(shù):
'FileAllowType------處理文件允許的類(lèi)型,定義方法例:gif|jpg|png|txt
'FileNewDir------文件處理后保存到的目錄
'FileNewName------新文件名前綴,請(qǐng)不要添加后綴,例:sample.txt則為sample
'CoverPr------是否覆蓋已有的文件0為否1為是默認(rèn)為1
'deletePr------是否刪除原文件0為否1為是默認(rèn)為1
'---------------------------------------------------------
'------UpDir(path)取path的父目錄
'path可為文件,也可為目錄
'------GetPrefixName(path)取文件名前綴
'path必須為文件,可為完整路徑,也可是單獨(dú)文件名
'------GetFileName(path)取文件名
'path必須為文件,可為完整路徑,也可是單獨(dú)文件名
'------GetExtensionName(path)取文件名后綴,不包含"."
'path必須為文件,可為完整路徑,也可是單獨(dú)文件名
'------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="指定要?jiǎng)?chuàng)建目錄已存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path)))then
FolderCreat="指定要?jiǎng)?chuàng)建的目錄路徑錯(cuò)誤"
ExitFunction
EndIf
fso.createFolder(Path)
FolderCreat=True
EndFunction
PublicFunctionFolderdelete(Path,FileIF)
IfNot(fso.FolderExists(Path))then
Folderdelete="指定要?jiǎng)h除的目錄不存在"
ExitFunction
EndIf
IfFileIF=1then
SetFsoFile=Fso.GetFolder(Path)
If(FsoFile.SubFolders.count>0orFsoFile.Files.count>0)then
SetFsoFile=Nothing
Folderdelete="只要要?jiǎng)h除的目錄下含有文件或子目錄,不允許刪除"
ExitFunction
EndIf
SetFsoFile=Nothing
EndIf
Fso.deleteFolder(Path)
Folderdelete=True
EndFunction
PublicFunctionFileCopy(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileCopy="指定要復(fù)制的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileCopy="指定要復(fù)制到的目錄不存在"
ExitFunction
EndIf
IfCoverIF=0andfso.FileExists(Path_To)then
FileCopy="指定要復(fù)制到的目錄下已存在相同名稱(chēng)文件,不允許覆蓋"
ExitFunction
EndIf
fso.CopyFilePath_From,Path_To
FileCopy=True
EndFunction
PublicFunctionFileMove(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileMove="指定要移動(dòng)的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileMove="指定要移動(dòng)到的目錄不存在"
ExitFunction
EndIf
Iffso.FileExists(Path_To)then
IfCoverIF=0then
FileMove="指定要移動(dòng)到的目錄下已存在相同名稱(chēng)文件,不允許覆蓋"
ExitFunction
Else
CallFiledelete(Path_To)
EndIf
EndIf
fso.MoveFilePath_From,Path_To
FileMove=True
EndFunction
PublicFunctionFiledelete(Path)
IfNot(fso.FileExists(Path))then
Filedelete="指定要?jiǎng)h除的文件不存在"
ExitFunction
EndIf
Fso.deleteFilePath
Filedelete=True
EndFunction
PublicFunctionFilerename(OldName,NewName,CoverIf)
NewName=NewName&"."&GetExtensionName(OldName)
IfGetFileName(OldName)=NewNamethen
Filerename="更改前的文件與更改后的文件名稱(chēng)相同"
ExitFunction
ElseIfNot(fso.FileExists(OldName))then
Filerename="指定更改名稱(chēng)的文件不存在"
ExitFunction
ElseIffso.FileExists(UpDir(OldName)&"\"&NewName)then
IfCoverIf=0then
Filerename="目錄下已存在與更改后的文件名稱(chēng)相同的文件,不允許覆蓋"
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="此操作執(zhí)行后并未對(duì)指定文件產(chǎn)生變動(dòng),系統(tǒng)自動(dòng)中止"
ExitFunction
ElseIfFile_Path=""orNot(fso.FileExists(File_Path))then
FileRun="要進(jìn)行操作的文件不存在"
ExitFunction
ElseIfInstr(File_AllowType,GetExtensionName(File_Path))=0then
FileRun="要進(jìn)行操作的文件被系統(tǒng)拒絕,允許的格式為:"&Replace(File_AllowType,"|","")
ExitFunction
EndIf
IfFile_NewFolder_Path=""then
File_NewFolder_Path=UpDir(File_Path)
ElseIfNot(fso.FolderExists(File_NewFolder_Path))then
FileRun="指定要移動(dòng)到的目錄不存在"
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="此操作執(zhí)行后并未對(duì)指定文件產(chǎn)生變動(dòng),系統(tǒng)自動(dòng)中止"
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系統(tǒng)FSO操作類(lèi)Beta1*****************************
'調(diào)用方法:SetObj=NewFSOControl
'所有路徑必須為絕對(duì)路徑,請(qǐng)采用Server.MapPath方法轉(zhuǎn)換路徑后再定義變量
'------FileRun---------------------------------------
'
'必選參數(shù):
'FilePath------處理文件路徑
'
'可選參數(shù):
'FileAllowType------處理文件允許的類(lèi)型,定義方法例:gif|jpg|png|txt
'FileNewDir------文件處理后保存到的目錄
'FileNewName------新文件名前綴,請(qǐng)不要添加后綴,例:sample.txt則為sample
'CoverPr------是否覆蓋已有的文件0為否1為是默認(rèn)為1
'deletePr------是否刪除原文件0為否1為是默認(rèn)為1
'---------------------------------------------------------
'------UpDir(path)取path的父目錄
'path可為文件,也可為目錄
'------GetPrefixName(path)取文件名前綴
'path必須為文件,可為完整路徑,也可是單獨(dú)文件名
'------GetFileName(path)取文件名
'path必須為文件,可為完整路徑,也可是單獨(dú)文件名
'------GetExtensionName(path)取文件名后綴,不包含"."
'path必須為文件,可為完整路徑,也可是單獨(dú)文件名
'------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="指定要?jiǎng)?chuàng)建目錄已存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path)))then
FolderCreat="指定要?jiǎng)?chuàng)建的目錄路徑錯(cuò)誤"
ExitFunction
EndIf
fso.createFolder(Path)
FolderCreat=True
EndFunction
PublicFunctionFolderdelete(Path,FileIF)
IfNot(fso.FolderExists(Path))then
Folderdelete="指定要?jiǎng)h除的目錄不存在"
ExitFunction
EndIf
IfFileIF=1then
SetFsoFile=Fso.GetFolder(Path)
If(FsoFile.SubFolders.count>0orFsoFile.Files.count>0)then
SetFsoFile=Nothing
Folderdelete="只要要?jiǎng)h除的目錄下含有文件或子目錄,不允許刪除"
ExitFunction
EndIf
SetFsoFile=Nothing
EndIf
Fso.deleteFolder(Path)
Folderdelete=True
EndFunction
PublicFunctionFileCopy(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileCopy="指定要復(fù)制的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileCopy="指定要復(fù)制到的目錄不存在"
ExitFunction
EndIf
IfCoverIF=0andfso.FileExists(Path_To)then
FileCopy="指定要復(fù)制到的目錄下已存在相同名稱(chēng)文件,不允許覆蓋"
ExitFunction
EndIf
fso.CopyFilePath_From,Path_To
FileCopy=True
EndFunction
PublicFunctionFileMove(Path_From,Path_To,CoverIF)
IfNot(fso.FileExists(Path_From))then
FileMove="指定要移動(dòng)的文件不存在"
ExitFunction
ElseIfNot(fso.FolderExists(UpDir(Path_To)))then
FileMove="指定要移動(dòng)到的目錄不存在"
ExitFunction
EndIf
Iffso.FileExists(Path_To)then
IfCoverIF=0then
FileMove="指定要移動(dòng)到的目錄下已存在相同名稱(chēng)文件,不允許覆蓋"
ExitFunction
Else
CallFiledelete(Path_To)
EndIf
EndIf
fso.MoveFilePath_From,Path_To
FileMove=True
EndFunction
PublicFunctionFiledelete(Path)
IfNot(fso.FileExists(Path))then
Filedelete="指定要?jiǎng)h除的文件不存在"
ExitFunction
EndIf
Fso.deleteFilePath
Filedelete=True
EndFunction
PublicFunctionFilerename(OldName,NewName,CoverIf)
NewName=NewName&"."&GetExtensionName(OldName)
IfGetFileName(OldName)=NewNamethen
Filerename="更改前的文件與更改后的文件名稱(chēng)相同"
ExitFunction
ElseIfNot(fso.FileExists(OldName))then
Filerename="指定更改名稱(chēng)的文件不存在"
ExitFunction
ElseIffso.FileExists(UpDir(OldName)&"\"&NewName)then
IfCoverIf=0then
Filerename="目錄下已存在與更改后的文件名稱(chēng)相同的文件,不允許覆蓋"
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="此操作執(zhí)行后并未對(duì)指定文件產(chǎn)生變動(dòng),系統(tǒng)自動(dòng)中止"
ExitFunction
ElseIfFile_Path=""orNot(fso.FileExists(File_Path))then
FileRun="要進(jìn)行操作的文件不存在"
ExitFunction
ElseIfInstr(File_AllowType,GetExtensionName(File_Path))=0then
FileRun="要進(jìn)行操作的文件被系統(tǒng)拒絕,允許的格式為:"&Replace(File_AllowType,"|","")
ExitFunction
EndIf
IfFile_NewFolder_Path=""then
File_NewFolder_Path=UpDir(File_Path)
ElseIfNot(fso.FolderExists(File_NewFolder_Path))then
FileRun="指定要移動(dòng)到的目錄不存在"
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="此操作執(zhí)行后并未對(duì)指定文件產(chǎn)生變動(dòng),系統(tǒng)自動(dòng)中止"
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
%>
轉(zhuǎn)自
落伍者
原作者: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";
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
