private sub command1_click()
dim strpathname as string
strpathname = ""
strpathname = inputbox("請(qǐng)輸入需要?jiǎng)h除的文件夾名稱∶", "刪除文件夾")
if strpathname = "" then exit sub
on error goto errorhandle
setattr strpathname, vbnormal '此行主要是為了檢查文件夾名稱的有效性
recursetree strpathname
label1.caption = "文件夾" & strpathname & "已經(jīng)刪除!"
exit sub
errorhandle:
msgbox "無(wú)效的文件夾名稱:" & strpathname
end sub
sub recursetree(currpath as string)
dim sfilename as string
dim newpath as string
dim spath as string
static oldpath as string
spath = currpath & "/"
sfilename = dir(spath, 31) '31的含義∶31=vbnormal+vbreadonly+vbhidden+vbsystem+vbvolume+vbdirectory
do while sfilename <> ""
if sfilename <> "." and sfilename <> ".." then
if getattr(spath & sfilename) and vbdirectory then '如果是目錄和文件夾
newpath = spath & sfilename
recursetree newpath
sfilename = dir(spath, 31)
else
setattr spath & sfilename, vbnormal
kill (spath & sfilename)
label1.caption = spath & sfilename '顯示刪除過(guò)程
sfilename = dir
end if
else
sfilename = dir
end if
doevents
loop
setattr currpath, vbnormal
rmdir currpath
label1.caption = currpath
end sub
新聞熱點(diǎn)
疑難解答
圖片精選