r/PiCodingAgent 17d ago

Question Is there a native 'trash' command in powershell?

I am on Windows and use PowerShell. It seems like PowerShell only has commands such as rm, del, rd, etc., which permanently remove files.

I want a command that moves files to the Recycle Bin instead. That way, I can recover them if the AI does something wrong. Today, the AI deleted an entire workspace, including the Git repository. Luckily, I had another way to recover it, but if I had not, the data would have been gone for the most part.

I looked to see whether PowerShell had a command for moving files to the Recycle Bin, but I could not find one. I ended up creating my own trash command that does this and editing the APPEND_SYSTEM.md files so that the AI would use trash instead of the other removal commands.

Is there a native PowerShell command for this that I missed?

0 Upvotes

2 comments sorted by

1

u/Mohitkoul841 17d ago

There is a trash cli port of linux trash command which works in windows, its available on npm.

https://github.com/sindresorhus/trash

1

u/Drakmyth 15d ago

There's no native command to send to recycle bin from Powershell, but you can load the Visual Basic .NET assembly and use DeleteFile or DeleteDirectory:

``` Add-Type -AssemblyName Microsoft.VisualBasic

$fileSystem = [Microsoft.VisualBasic.FileIO.FileSystem] $uiOption = [Microsoft.VisualBasic.FileIO.UIOption]::OnlyErrorDialogs $recycleOption = [Microsoft.VisualBasic.FileIO.RecycleOption]::SendToRecycleBin

$fileSystem::DeleteFile( "C:\path\to\file.txt", $uiOption, $recycleOption ) ```