Deltree Example
Keywords: deltree
Also see the File Searcher Extender help file, for another deltree example.
;********************************************************
;Example to clear the directory C:\Temp
delpath="C:\Temp\"
Gosub s_deltree
;s_deltree delete all files and subdirectorys in a spezified
;directory no recursion is required
;***********************************************************
;used variables: delpath - must contain the path to directory to clear
; s_deltree_succes - TRUE, if s_deltree was o.k.
:s_deltree
brkvar = @TRUE ;set breakcondition
s_deltree_succes=@FALSE
;Make sure the path has a \ on the end,
If StrSub(delpath,StrLen(delpath),1)<>"\"
delpath=StrCat(delpath,"\")
EndIf
tpath=delpath ;save the original path
If DirExist(delpath) ;is path correct?
;workingloop
While brkvar
tempitem = DirItemize("%tpath%*.*")
If tempitem==""
If delpath==tpath ;all subdirectorys delete?
FileDelete ("%tpath%*.*")
brkvar=@FALSE
Else ;no more subdirectorys in this directory
FileDelete ("%tpath%*.*")
DirRemove (tpath)
tpath=StrSub (tpath, 1, StrScan (tpath, "\", StrLen (tpath)-1, @BACKSCAN))
EndIf
Else ;go one directory upstairs
tpath=StrCat(tpath,StrSub(tempitem,1,StrScan(tempitem,@TAB,1,@FWDSCAN)-1),"\")
EndIf
EndWhile
s_deltree_succes=@TRUE ;s_deltree was working correct
EndIf
Return
Article ID: W13804
Filename: Take Your Pick - Another Deltree Example.txt