Solved

progress bar

Posted on 2001-09-03
9
269 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now