Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - empty recycle bin

Reply
 
Old 06-06-2009   #1 (permalink)
Ryan


 
 

empty recycle bin

I need to write a simple script that will empty the recycle bin on a single
desktop computer.
--
Ryan
Denver, CO

My System SpecsSystem Spec
Old 06-06-2009   #2 (permalink)
Mike Pfeiffer


 
 

RE: empty recycle bin

This should work:

$objShell = New-Object -Com Shell.Application
$objFolder = $objShell.Namespace(0xA)
$objFSO = New-Object -ComObject Scripting.FileSystemObject

foreach ($item in $objFolder.Items()) {
If ($item.type -eq "File Folder")
{
$objFSO.DeleteFolder($item.path)
}
Else {
$objFSO.DeleteFile($item.path)
}
}

"Ryan" wrote:
Quote:

> I need to write a simple script that will empty the recycle bin on a single
> desktop computer.
> --
> Ryan
> Denver, CO
My System SpecsSystem Spec
Old 06-07-2009   #3 (permalink)
Alex K. Angelopoulos


 
 

Re: empty recycle bin

One shortcut that can simplify this further is to use Remove-Item; that
reduces it to a 2-line solution:

$objShell = New-Object -Com Shell.Application
$objShell.Namespace(0xA).Items() | Remove-Item -Recurse

And in the obligatory "oh yeah, it can be a one-liner" form :

(New-Object -Com Shell.Application).Namespace(0xA).Items()| ri -r


"Mike Pfeiffer" <MikePfeiffer@xxxxxx> wrote in message
news:A69F8DD8-F9B8-4AE0-ABF5-4A6D5C27AD0F@xxxxxx
Quote:

> This should work:
>
> $objShell = New-Object -Com Shell.Application
> $objFolder = $objShell.Namespace(0xA)
> $objFSO = New-Object -ComObject Scripting.FileSystemObject
>
> foreach ($item in $objFolder.Items()) {
> If ($item.type -eq "File Folder")
> {
> $objFSO.DeleteFolder($item.path)
> }
> Else {
> $objFSO.DeleteFile($item.path)
> }
> }
>
> "Ryan" wrote:
>
Quote:

>> I need to write a simple script that will empty the recycle bin on a
>> single
>> desktop computer.
>> --
>> Ryan
>> Denver, CO
My System SpecsSystem Spec
Old 06-07-2009   #4 (permalink)
Al Dunbar


 
 

Re: empty recycle bin


"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
wrote in message news:u5tcnc55JHA.4116@xxxxxx
Quote:

> One shortcut that can simplify this further is to use Remove-Item; that
> reduces it to a 2-line solution:
>
> $objShell = New-Object -Com Shell.Application
> $objShell.Namespace(0xA).Items() | Remove-Item -Recurse
>
> And in the obligatory "oh yeah, it can be a one-liner" form :
>
> (New-Object -Com Shell.Application).Namespace(0xA).Items()| ri -r
One-liner, nothing. I'm still waiting for someone to come up with a
zero-liner solution! Now that would be truly something. Or perhaps nothing.

/Al
Quote:

> "Mike Pfeiffer" <MikePfeiffer@xxxxxx> wrote in message
> news:A69F8DD8-F9B8-4AE0-ABF5-4A6D5C27AD0F@xxxxxx
Quote:

>> This should work:
>>
>> $objShell = New-Object -Com Shell.Application
>> $objFolder = $objShell.Namespace(0xA)
>> $objFSO = New-Object -ComObject Scripting.FileSystemObject
>>
>> foreach ($item in $objFolder.Items()) {
>> If ($item.type -eq "File Folder")
>> {
>> $objFSO.DeleteFolder($item.path)
>> }
>> Else {
>> $objFSO.DeleteFile($item.path)
>> }
>> }
>>
>> "Ryan" wrote:
>>
Quote:

>>> I need to write a simple script that will empty the recycle bin on a
>>> single
>>> desktop computer.
>>> --
>>> Ryan
>>> Denver, CO
>


My System SpecsSystem Spec
Old 06-15-2009   #5 (permalink)
Alex K. Angelopoulos


 
 

Re: empty recycle bin

"Al Dunbar" <alandrub@xxxxxx> wrote in message
news:Oxn$9k65JHA.5920@xxxxxx
Quote:

>
> "Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
> wrote in message news:u5tcnc55JHA.4116@xxxxxx
Quote:

>> One shortcut that can simplify this further is to use Remove-Item; that
>> reduces it to a 2-line solution:
>>
>> $objShell = New-Object -Com Shell.Application
>> $objShell.Namespace(0xA).Items() | Remove-Item -Recurse
>>
>> And in the obligatory "oh yeah, it can be a one-liner" form :
>>
>> (New-Object -Com Shell.Application).Namespace(0xA).Items()| ri -r
>
> One-liner, nothing. I'm still waiting for someone to come up with a
> zero-liner solution! Now that would be truly something. Or perhaps
> nothing.
>
In the long run, emptying the recycle bin IS a zero-liner solution. Thanks
to the Windows "garbage collector". ; )



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
I can't empty my recycle bin Vista file management
5K in Recycle Bin - 5 minutes to empty? Vista performance & maintenance
Recycle Bin won't empty Vista General
Can't Empty the Recycle Bin Vista General
Recycle Bin Will Not Empty Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46