David Reed"s Entry for the Custom RemoveEmptyFolders Delphi Function
Question: David Reed's Entry for the Custom RemoveEmptyFolders Delphi Function
Challenge: a custom Delphi function, RemoveEmptyFolders, should take a path name (directory) and should remove / delete all empty sub-folders at any (sub) level.
The code is submitted for the RemoveEmptyFolders Delphi Challenge
Answer:
RemoveEmptyFolders entry by David Reed:
Explore the list of all accepted entries for RemoveEmptyFolders Delphi challenge.
Challenge: a custom Delphi function, RemoveEmptyFolders, should take a path name (directory) and should remove / delete all empty sub-folders at any (sub) level.
The code is submitted for the RemoveEmptyFolders Delphi Challenge
Answer:
RemoveEmptyFolders entry by David Reed:
procedure RemoveEmptyFolders(const rootFolder : string) ; var fd: TWin32FindData; h: THandle; rf: string; begin rf := IncludeTrailingBackslash(rootFolder) ; h := FindFirstFile(PChar(rf + '*.*'), fd) ; if h <> INVALID_HANDLE_VALUE then try with fd do repeat if (dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY > 0) and (Pos(cFileName,'.;..') = 0) then begin if not RemoveDir(rf + cFilename) then RemoveEmptyFolders(rf + cFileName) ; end; until not FindNextFile(h,fd) ; finally Windows.FindClose(h) ; end; end;
Explore the list of all accepted entries for RemoveEmptyFolders Delphi challenge.
Source...