Deleting files with sending them to Recycle Bin [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Deleting files with sending them to Recycle Bin [SOLVED]

#1 Post by DOSadnie » 15 Jul 2023 05:03

A script like this

Code: Select all

del /q C:\Test
does delete files in that folder - but unfortunately without a fail-safe in form of sending them the Recycle Bin

So how can I delete files not so permanently?

[And no: I do not want to use a post-mistake workaround of using recovery tools]
Last edited by DOSadnie on 25 Jul 2023 14:18, edited 3 times in total.


koko
Posts: 38
Joined: 13 Oct 2016 00:40

Re: Deleting but with sending items to Recycle Bin

#3 Post by koko » 19 Jul 2023 08:31

There's a CLI program called binit that sends things to the recycle bin. In my testing it handled all the Unicode characters I tried, unlike another program (CmdUtils) that I'd seen suggested elsewhere. Not open source fwiw. The author posted their motivation for creating it on Stack Overflow.

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Deleting but with sending items to Recycle Bin

#4 Post by DOSadnie » 19 Jul 2023 10:09

What does the present in it

Code: Select all

"Usage (prints with default printer a file if possible)"
suppose to have anything to do with deletion of items and Recycle Bin?


koko wrote:
19 Jul 2023 08:31
There's a CLI program called binit that sends things to the recycle bin
[...]
OK

But how can I effectively use Binit also outside of a BAT script, i.e. incorporate it to a daily and on the spot usage?

I would have to write and always be running e.g. AHK script that would replace pressing of Delete key in every program of mine that happens to have file handling abilities with the usage of this Binit; plus I would need to add a fail-safe question for it. And then I would also need to add Binit [also with a fail-safe step] to my right click menu, right?
Last edited by DOSadnie on 19 Jul 2023 11:01, edited 2 times in total.

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Deleting but with sending items to Recycle Bin

#5 Post by DOSadnie » 19 Jul 2023 10:44

DOSadnie wrote:
19 Jul 2023 10:09
OK

But how how can I effectively use Binit also outside of a BAT script
[...]
Hold your horses


If I will execute a BAT like this

Code: Select all

cd "C:\My Portables\Binit\"
start "" /b Binit.exe "M:\Music\*.WAV"
then it will delete files only from the Music folder - and the PDF help file for Binit says nothing about ability to include subfolders

Thus it seems this is useful only for a very specified job, like a temp file of some sort or something like that run e.g. right after a startup of Windows or closure of some program

koko
Posts: 38
Joined: 13 Oct 2016 00:40

Re: Deleting but with sending items to Recycle Bin

#6 Post by koko » 19 Jul 2023 11:56

DOSadnie wrote:
19 Jul 2023 10:09
But how can I effectively use Binit also outside of a BAT script, i.e. incorporate it to a daily and on the spot usage?
You'd use it like any CLI program. I mean, that's what you're doing in the OP.
DOSadnie wrote:
19 Jul 2023 10:09
I would have to write and always be running e.g. AHK script that would replace pressing of Delete key in every program of mine that happens to have file handling abilities with the usage of this Binit; plus I would need to add a fail-safe question for it. And then I would also need to add Binit [also with a fail-safe step] to my right click menu, right?
? Your OP describes a CLI usage but now you're wanting to replace the native Windows functionality of the delete key and context menu... with a program that does the same thing (ie: both send files to the Recycle Bin)? I don't understand.

Anyway, I've used it in a script before and it's useful.

Edit: also if you want a program to be accessible from any directory, just by typing the program's name (eg: binit), you'll have to add the program to a directory in the Windows PATH environment variable. This part is kind of assumed knowledge when discussing CLI programs.
Last edited by koko on 20 Jul 2023 00:25, edited 2 times in total.

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Deleting but with sending items to Recycle Bin

#7 Post by npocmaka_ » 19 Jul 2023 12:06

DOSadnie wrote:
19 Jul 2023 10:09
What does the present in it

Code: Select all

"Usage (prints with default printer a file if possible)"
suppose to have anything to do with deletion of items and Recycle Bin?


koko wrote:
19 Jul 2023 08:31
There's a CLI program called binit that sends things to the recycle bin
[...]
OK

But how can I effectively use Binit also outside of a BAT script, i.e. incorporate it to a daily and on the spot usage?

I would have to write and always be running e.g. AHK script that would replace pressing of Delete key in every program of mine that happens to have file handling abilities with the usage of this Binit; plus I would need to add a fail-safe question for it. And then I would also need to add Binit [also with a fail-safe step] to my right click menu, right?
Haha. THis is something that I've copied from another script. Thanks. I'll update it. To use it you need just to pass a file or folder location as an argument:

Code: Select all

call deleteJs.bat c:\myfolder\myFile.txt

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Deleting but with sending items to Recycle Bin

#8 Post by Batcher » 24 Jul 2023 02:33

test-1.bat

Code: Select all

@echo off
set "MyFile=C:\Test\1.txt"
mshta "javascript:new ActiveXObject('Shell.Application').NameSpace(10).CopyHere('%MyFile:\=\\%');close()"

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Deleting but with sending items to Recycle Bin

#9 Post by DOSadnie » 24 Jul 2023 14:49

I tested this java script out and it works. Unfortunately I have failed at such basic reworking of it as applying it to

Code: Select all

*.WAV

As for the question of
koko wrote:
19 Jul 2023 11:56
[...]
replace the native Windows functionality of the delete key and context menu... with a program that does the same thing (ie: both send files to the Recycle Bin)? I don't understand.
[...]
I also having read carefully more than once what I had written do not understand what was it that I was after back then

It is just another case of me attempting to do too many tweaks with scripts at the same time and writing about them on various forums


However I have come up with apparently A-OK working solution with this PS1 script:

Code: Select all

$LIST_OF_FOLDERS_TO_APPLY_THIS_SCRIPT = @(
    "M:\Music\",
    "X:\Music New\",
    "Z:\Backups\"
)

$EXTENSION_OF_FILES_TO_REMOVE = "*.WAV"

function DELETE-FILES($FOLDER) {
    $THIS_WILL_BE_REMOVED = Get-ChildItem -Path $FOLDER -Filter $EXTENSION_OF_FILES_TO_REMOVE -File -Force -ErrorAction SilentlyContinue

    foreach ($file in $THIS_WILL_BE_REMOVED) {
        $shell = New-Object -ComObject Shell.Application
        $shell.Namespace(10).MoveHere($file.FullName)
    }

    $ALL_SUBFOLDERS = Get-ChildItem -Path $FOLDER -Directory -Force -ErrorAction SilentlyContinue
    foreach ($EACH_SUBFOLDER in $ALL_SUBFOLDERS) {
        DELETE-FILES $EACH_SUBFOLDER.FullName
    }
}

foreach ($FOLDER_PATH in $LIST_OF_FOLDERS_TO_APPLY_THIS_SCRIPT_TO) {
    DELETE-FILES $FOLDER_PATH
}
And so for now all I will not be pursuing usage of other methods - but nevertheless I will keep a link to this discussion and its offline
copy


And thank you all for your input so far

Post Reply