Link to home
Start Free TrialLog in
Avatar of Bosanac
Bosanac

asked on

progress bar

How can I activate progress bar while deleting file?
For a nicer look,he,he....
Avatar of CrazyOne
CrazyOne
Flag of United States of America image

Well if it is just on file it won't really matter because the DeleteFile does just that it doesn't return any data as to how much of the file it has deleted. However if you are doing more than one file then you could use a progress bar to indicate how far along the delete process has gotten. This code presumes you know what the files you will be deleting are. If it is a generic deletion then modify the code to fit it to your needs.

procedure TForm1.Button1Click(Sender: TObject);
var
     i: Integer;

const
     sFilesToDel: array[1..4] of string = ('C:\File.0', 'C:\File.1', 'C:\File.2', 'C:\File.3');

begin

     with ProgressBar1 do begin
          Min := 0;
          Max := High(sFilesToDel);
          Position := Min ;
          for i := Low(sFilesToDel) to High(sFilesToDel) do begin
               DeleteFile(sFilesToDel[i]);
               Position := i;
          end;

     end;

end;


The Crazy One
Avatar of lucika
lucika

Still it is necessary to make Application.ProcessMessages after string(line) " Possition: = i "
Use the Win API call, SHFileOperation, which will copy, remove, delete and rename files and show the standard Windows dialog box at the same time.

J.
ASKER CERTIFIED SOLUTION
Avatar of Jason Sweby
Jason Sweby
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi jsweby
Good suggestion. I have used SHFileOperation on occasions but the problem I have had with it is that when it comes across a file that causes a sharing violation the process completely stops at that point and won't resume on its own. Do you have Any ideas how to get pass this problem? Thanks :>)
To tell you the truth, no, I wasn't aware of this problem and have no resolution for it. Windows is the same though, if you're copying files and there is a sharing violation error message, the copy stops, it doesn't resume, so I guess in that respect you're emulating Windows perfectly, ideally or not.

J.
Thanks J
Perhaps Windows uses the same function hence the emulation affect.
Windows does use this exact function for its file operations, it is a direct call to the same Windows API command.
Avatar of Bosanac

ASKER

T! and to rest...