Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Delete Empty Directories

 Keywords:  Delete Empty Directories

Sample:

#DefineFunction DeleteEmptyDirectories(Root)
;
;  Examine every directory under the root.
;  Delete them if they are empty.
;  Return the number of items in ROOT
;
    DirList = DirItemize(StrCat(Root,"\*.*"))
    Total = 0
    while @TRUE
        NextDir = ItemExtract(1,DirList,@TAB)
        if NextDir == "" then break
        DirList = ItemRemove(1,DirList,@TAB)
        NextDir = StrCat(Root,"\",NextDir)
        Count = DeleteEmptyDirectories(NextDir)
        if Count == 0
            DirRemove(NextDir)
        else
            Total = Total + Count + 1
        endif
    endwhile
    Count = ItemCount(FileItemize(StrCat(Root,"\*.*")),@TAB)
    Total = Total + Count
    return Total
#EndFunction

;-----------------------------------------------------------
;  Test the UDF
;-----------------------------------------------------------
TestDir = "C:\Temp\Test"
x = DeleteEmptyDirectories(TestDir)
if x == 0 then DirRemove(TestDir)

Article ID:   W15289