Solved

progress bar

Posted on 2001-09-03
9
272 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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