Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-23-2014, 10:38 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default Why does this not work anymore?

I used the following procedure since upgrading to XE6, now using XE7 this procedure no longer works , can anybody locate the problem?

Code:
procedure TForm1.actRemoveEmptyFoldersExecute(Sender: TObject);
var
  llist: TStringDynArray;
  i: Integer;
  LSearchOption: TSearchOption;
  oname: string;
begin
  LSearchOption := TSearchOption.soAllDirectories;
  llist := TDirectory.GetDirectories(Form1.DirectoryListBox1.Directory, '*.*',
    LSearchOption);
  showmessage(inttostr(length(llist)) + ' Folders Found');// message box for debuging
  for i := length(llist) - 1 downto 0 do
  begin
    showstatus(0,length(llist) - 1,i,'Checking:',llist[i]); //Updates Status Bar
   if TDirectory.IsEmpty(llist[i]) then
   begin
   Tdirectory.Delete(llist[i]) ;
   end;
  end;
  DirectoryListBox1.Update;
end;
I cannot seem to find a problem, or is there a better way to do this, I am trying to pass a file path and delete all empty sub folders.
Reply With Quote
  #2  
Old 12-24-2014, 04:48 PM
major major is offline
Senior Member
 
Join Date: Jun 2011
Posts: 150
Default

Not sure what you consider "no longer working" but I suspect what may be happening, consider the outcome when you have a non-empty directory, but all it contains is an empty or list of empty sub-directories.

Because your search options are TSearchOption.soAllDirectories, It would delete all the empty subdirectories, and then that original non-empty directory is now empty, since all its empty subdirectories have been deleted, but it has itself not been deleted, because when you tested "if TDirectory.IsEmpty(llist[i])" it evaluated to false.
Reply With Quote
  #3  
Old 12-25-2014, 12:00 AM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default

The problem is that the sub directories are not getting deleted, the path that is passed to the function does not need to be deleted, just need to empty it of all empty folders.
Reply With Quote
Reply

Tags
delete, directory, empty, files

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 04:56 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.