?
Solved

progress bar

Posted on 2001-09-03
9
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Accepted Solution

by:
jsweby earned 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 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