Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Get-ChildItem -recurse | Where {$_.PSIsContainer -and `
@(Get-ChildItem -Lit $_.Fullname -r | Where {!$_.PSIsContainer}).Length -eq 0} |
Remove-Item -recurse -whatif

now i can use the above PowerShell script to delete files permanently, but now i want the files be removed to recyle bin?

any one can help me?
Posted

 
Share this answer
 
Look at these ones (source[^]). Not elegant, since they invoke COM :(, but should work:
$shell = new-object -comobject "Shell.Application"
$path = "<the path to the file>"
$item = $shell.Namespace(0).ParseName("$path")
$item.InvokeVerb("delete")

or
$shell = new-object -comobject "Shell.Application"
$folder = $shell.Namespace("<path to="" file="">")
$item = $folder.ParseName("<name of="" file="">")
$item.InvokeVerb("delete")</name></path>


This one could be also useful for you: http://tfl09.blogspot.hu/2007/01/manipulating-recycle-bin-in-powershell.html[^]

But I am wondering why do you want to move something from code to recycle bin? If you need a backup, move/copy it to a folder created by you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900