Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to send files to the recycle bin Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
20-Oct-02
Category
Files Operation
Language
Delphi 2.x
Views
114
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to send files to the recycle bin

Answer:

Solve 1:


1   unit Recycle;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, ShellAPI;
7   
8   function RecycleFile(FileToRecycle: TFilename): boolean;
9   function RecycleFileEx(FileToRecycle: TFilename; Confirm: boolean): boolean;
10  
11  implementation
12  
13  function RecycleFile(FileToRecycle: TFilename): boolean;
14  begin
15    Result := RecycleFileEx(FileToRecycle, True);
16  end;
17  
18  function RecycleFileEx(FileToRecycle: TFilename; Confirm: boolean): boolean;
19  var
20    Struct: TSHFileOpStruct;
21    tmp: string;
22    Resultval: integer;
23  begin
24    tmp := FileToRecycle + #0#0;
25    Struct.wnd := 0;
26    Struct.wFunc := FO_DELETE;
27    Struct.pFrom := PChar(tmp);
28    Struct.pTo := nil;
29    Struct.fFlags := FOF_ALLOWUNDO;
30    if not Confirm then
31      Struct.fFlags := Struct.fFlags or FOF_NOCONFIRMATION;
32    Struct.fAnyOperationsAborted := false;
33    Struct.hNameMappings := nil;
34    try
35      Resultval := ShFileOperation(Struct);
36    except
37      on e: Exception do
38      begin
39        e.message := 'Tried to recycle file:' + FileToRecycle + #13#10 + e.message;
40        raise;
41      end;
42    end;
43    Result := (Resultval = 0);
44  end;
45  
46  end.



Solve 2:

47  uses ShellApi;
48  
49  function DeleteFilesToRecycleBin(const APath: string): Boolean;
50  var
51    AStruct: TShFileOpStruct;
52  begin
53    if Length(APath) = 0 then
54      Exit;
55    AStruct.Wnd := 0;
56    AStruct.wFunc := FO_DELETE;
57    AStruct.pFrom := PChar(APath);
58    AStruct.fFlags := FOF_ALLOWUNDO;
59    Result := ShFileOperation(AStruct) <> 0;
60  end;



Solve 3:

61  function RecycleFile(FileToRecycle: string): boolean;
62  var
63    Struct: TSHFileOpStruct;
64    pFromc: PChar;
65    Resultval: integer;
66  begin
67    if not FileExists(FileToRecycle) then
68    begin
69      RecycleFile := False;
70      exit;
71    end
72    else
73    begin
74      pfromc := PChar(ExpandFileName(FileToRecycle) + #0#0);
75      Struct.wnd := 0;
76      Struct.wFunc := FO_DELETE;
77      Struct.pFrom := pFromC;
78      Struct.pTo := nil;
79      Struct.fFlags := FOF_ALLOWUNDO;
80      Struct.fAnyOperationsAborted := false;
81      Struct.hNameMappings := nil;
82      Resultval := ShFileOperation(Struct);
83      RecycleFile := (Resultval = 0);
84    end;
85  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC