WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Directory and Deltree UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

UDF Delete Empty Directories

Keywords: 	 UDF Delete Empty Directories

The following UDF examine every directory under the root, then deletes them if they're empty. And it returns the number of items in ROOT.
#DefineFunction DeleteDirectories(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 = DeleteDirectories(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:\Windows\Desktop\Test"
x = DeleteDirectories(TestDir)
if x == 0 then DirRemove(TestDir)



Article ID:   W15319
File Created: 2002:09:05:13:51:20
Last Updated: 2002:09:05:13:51:20