Solved

progress bar

Posted on 2001-09-03
9
271 Views
Last Modified: 2010-04-06
How can I activate progress bar while deleting file?
For a nicer look,he,he....
0
Comment
Question by:Bosanac
9 Comments
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6452223
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
0
 
LVL 2

Expert Comment

by:lucika
ID: 6453588
Still it is necessary to make Application.ProcessMessages after string(line) " Possition: = i "
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6457307
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.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 4

Accepted Solution

by:
jsweby earned 50 total points
ID: 6457341
The following example demonstrates using the SHFileOperation function to copy a group of files and display a progress dialog. You can also use the following flags to delete, move and rename a group of files.
 
TO_COPY
FO_DELETE
FO_MOVE
FO_RENAME
 
Note: The buffer that contains the file names to copy must
end with a double null terminating character;
 
Example:
 
uses ShellAPI;
 
procedure TForm1.Button1Click(Sender: TObject);
var
 Fo      : TSHFileOpStruct;
 buffer  : array[0..4096] of char;
 p       : pchar;
 
begin
  FillChar(Buffer, sizeof(Buffer), #0);
  p := @buffer;
  p := StrECopy(p, 'C:\DownLoad\1.ZIP') + 1;
  p := StrECopy(p, 'C:\DownLoad\2.ZIP') + 1;
  p := StrECopy(p, 'C:\DownLoad\3.ZIP') + 1;
  StrECopy(p, 'C:\DownLoad\4.ZIP');
 
  FillChar(Fo, sizeof(Fo), #0);
  Fo.Wnd    := Handle;
  Fo.wFunc  := FO_COPY;
  Fo.pFrom  := @Buffer;
  Fo.pTo    := 'D:\';
  Fo.fFlags := 0;
  if ((SHFileOperation(Fo) <> 0) or
      (Fo.fAnyOperationsAborted <> false)) then
    ShowMessage('Cancelled')
end;

J.
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6457469
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 :>)
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6457589
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.
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6457667
Thanks J
Perhaps Windows uses the same function hence the emulation affect.
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6457676
Windows does use this exact function for its file operations, it is a direct call to the same Windows API command.
0
 

Author Comment

by:Bosanac
ID: 7505492
T! and to rest...
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 110
Printing problem 2 95
Create a path if not exists 7 77
How to build JSON File in Delphi 6 3 34
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question