?
Solved

emptying recycle bin

Posted on 1998-12-18
18
Medium Priority
?
298 Views
Last Modified: 2010-04-04
Is there an api used that can empty the recycle bin?
If I have to recursively read through it to remove all the files and folders, is the recycle bin always located at
c:\recycled?  (or whatever drive windows is installed on).
0
Comment
Question by:jexd99
[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
  • 8
  • 6
  • 2
  • +2
18 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1351926
The only way I know is to recursively delete all the files and folders...   :-(
Use this function to get the path of the recycle bin:

function GetSpecialFolderPath(folder: cardinal; out path: string) : boolean;
var pidl   : PItemIDList;
    malloc : IMalloc;
begin
  path:='';
  result:=SHGetSpecialFolderLocation(INVALID_HANDLE_VALUE,folder,pidl)=NOERROR;
  if result then
    try
      SetLength(path,MAX_PATH);
      result:=SHGetPathFromIDList(pidl,pchar(path));
      if result then path:=string(pchar(result))
      else           path:='';
    finally
      if SHGetMalloc(malloc)=NOERROR then
        malloc.Free(pidl);
    end;
end;

If you have Delphi 3, then replace the "out" with "var". If you've Delphi 2 then you'll have to work a little bit at the COM objects.

Give in CSIDL_BITBUCKET as the folder. If you're interested in what paths you can get furthermore with this function look at the documentation of SHGetSpecialFolderLocation.

Regards, Madshi.
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1351927
There is a SHEmptyRecycleBin call that does the trick, I have some Delphi code somewhere, I'll try to dig it up..
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1351928
Hi BlackMan, ok, that would of course be much simpler (=better) than my suggestion...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:ronit051397
ID: 1351929
SHEmptyRecycleBin is not declared in D2/D3, you need declare it, see:
http://www.takenet.or.jp/~ryuuji/delphi/download/shellapi98.pas
0
 
LVL 7

Accepted Solution

by:
BlackMan earned 150 total points
ID: 1351930
Actually, my code is based on the library mentioned by ronit, so just download it and call SHEmptyRecycleBin(Application.Handle, '', 0) to empty the recycle bin.
By adding a combination of the option-constants instead on 0, you can change the behavoiur of the function...
0
 

Author Comment

by:jexd99
ID: 1351931
Thanks
0
 

Expert Comment

by:fredff13
ID: 2281146
Madshi's comment:
I used your function under Windows NT and get False result after function SHGetPathFromIDList(pidl,pchar(path)). Is it means that path for Recycle Bin is not exist?
BlackMan's answer:
I cannot use SHEmptyRecycleBin(Application.Handle, '', 0) because Windows message shows me that my Shell32.dll doesn't have SHEmptyRecycleBinA function.
I declared in my unit
function SHEmptyRecycleBin  ; external shell32 name 'SHEmptyRecycleBinA';
Still waiting for correct expert opinion.  
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2282577
Yes, you're right! That's really strange. We get a valid pidl, but it seems to be not part of the file system. Though the recycle directory IS part of the file system. I don't get it. Well, it's Micro$~1...   :-(

However, there was one bug in my function. So if you want to use it for other things, use this corrected version:

function GetSpecialFolderPath(folder: cardinal; out path: string) : boolean;
var pidl   : PItemIDList;
    malloc : IMalloc;
begin
  path:='';
  result:=SHGetSpecialFolderLocation(Application.Handle,folder,pidl)=NOERROR;
  if result then
    try
      SetLength(path,MAX_PATH);
      result:=SHGetPathFromIDList(pidl,pchar(path));
      if result then path:=string(pchar(path))
      else           path:='';
    finally
      if SHGetMalloc(malloc)=NOERROR then
        malloc.Free(pidl);
    end;
end;

Regards, Madshi.
0
 

Expert Comment

by:fredff13
ID: 2283537
I received answer from Daniel U. Thibault a.k.a. Urhixidur, that explained why it's impossible to use this function to find path for CSIDL_BITBUCKET:
"SHGetPathFromIDList will fail because the Recycle Bin exists in multiple places. Under Win95, it will have part of itself on each drive (C:\Recycled, D:\Recycled, etc.). Under WinNT, it gets
worse since it subdivides each Recycler (note the name change) directory according to the currently logged-on user. So, you can obtain the recycle bin's PIDL, but not its path."  
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2283675
Ah... Thanx for the info...   :-)
0
 

Expert Comment

by:fredff13
ID: 2284366
I can't update Shell32.dll from version 4.00 to 4.71 or above even after installing IE 5.01. If you can help me please.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2285814
What do you mean with you can't do that? Do you have the new dll version at hand? Where's the problem?
0
 

Expert Comment

by:fredff13
ID: 2286856
I got mail with next suggestion how to move to Shell32 enhancement:
"Believe it or not, you'll have to *uninstall* IE5 first, then install IE4 (basic install). Once IE4 is installed, when you click Add/Remove for Microsoft Internet Explorer 4 in the "Add/Remove
Programs" control panel, you'll be presented with a small set of choices, one of which is to get the Desktop Update. That's the one you want.
Once the Desktop Update is in place, you'll be able to re-install IE5, if you must (I prefer Netscape myself).
The Desktop Update changes the behaviour of the shell in all sorts of neat ways. One way you can tell it is in place is to bring up the Start Menu and then right-click on a Start Menu item."
So, I need make changes with Desktop Update. This is too complicated for me. Is there any other ways?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2286939
Ah, you meant not only this one little shell32.dll, but the complete IE4-system-upgrade!! That's quite a huge difference! IE4 with Desktop Update replaces large parts of the operating system. So you can almost move from win95 to win98. If you already have win98, you don't need that, but for win95 it's an interesting choice. That's right, you need to uninstall IE5 first...   :-(

Regards, Madshi.
0
 

Expert Comment

by:fredff13
ID: 2286969
Unfortunately, I have Windows NT! So... And some other PCs in our office with Windows 98 have right Shell32.dll!!! I cannot just copy this file over my system.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2287025
Well, okay, I think with NT it's the same story as with win95. IE4 will replace big parts of the user interface. So you'll have no other choice than to uninstall IE5...
0
 

Expert Comment

by:fredff13
ID: 2287141
Thank's, I just wondering if I after uninstall IE 5, and than eventually IE 4 with Desktop Upadate I'm not run into the much bigger problems.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2287279
Maybe...   :-)   :-((
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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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