在vb中删除带子文件夹的文件夹
2006-02-27 11:38:56 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁惧墽鎳撻—鍐偓锝庝簻椤掋垺銇勯幇顖毿撻柟渚垮妼椤粓宕卞Δ鈧獮濠勭磽閸屾艾鈧懓顫濋妸鈺佺疅缂佸顑欓崥瀣煕椤愵偅绶氱紓鍐╂礋濮婂宕掑▎鎴М濠电姭鍋撻梺顒€绉甸幆鐐哄箹濞n剙濡肩紒鎰殜閺屸€愁吋鎼粹€茬敖婵炴垶鎸哥粔鐢稿Φ閸曨垰鍐€妞ゆ劦婢€濞岊亪姊虹紒妯诲蔼闁稿海鏁诲濠氭晲婢跺﹤宓嗛梺缁樺姈缁佹挳宕戦幘璇叉嵍妞ゆ挻绋戞禍鐐叏濡厧浜鹃悗姘炬嫹

PRivateSubCommand1_Click()
DimstrPathNameAsString
strPathName=""
strPathName=InputBox("请输入需要删除的文件夹名称∶","删除文件夹")
IfstrPathName=""ThenExitSub
OnErrorGoToErrorHandle
SetAttrstrPathName,vbNormal'此行主要是为了检查文件夹名称的有效性
RecurseTreestrPathName
Label1.Caption="文件夹"&strPathName&"已经删除!"
ExitSub
ErrorHandle:
MsgBox"无效的文件夹名称:"&strPathName
EndSub
SubRecurseTree(CurrPathAsString)
DimsFileNameAsString
DimnewPathAsString
DimsPathAsString
StaticoldPathAsString
sPath=CurrPath&"\"
sFileName=Dir(sPath,31)'31的含义∶31=vbNormal vbReadOnly vbHidden vbSystem vbVolume vbDirectory
DoWhilesFileName<>""
IfsFileName<>"."AndsFileName<>".."Then
IfGetAttr(sPath&sFileName)AndvbDirectoryThen'如果是目录和文件夹
newPath=sPath&sFileName
RecurseTreenewPath
sFileName=Dir(sPath,31)
Else
SetAttrsPath&sFileName,vbNormal
Kill(sPath&sFileName)
Label1.Caption=sPath&sFileName'显示删除过程
sFileName=Dir
EndIf
Else
sFileName=Dir
EndIf
DoEvents
Loop
SetAttrCurrPath,vbNormal
RmDirCurrPath
Label1.Caption=CurrPath
EndSub
->更多精彩
赞助商链接