Page 1 of 1
Deleting files with sending them to Recycle Bin [SOLVED]
Posted: 15 Jul 2023 05:03
by DOSadnie
A script like this
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]
Re: Deleting but with sending items to Recycle Bin
Posted: 19 Jul 2023 02:39
by npocmaka_
Re: Deleting but with sending items to Recycle Bin
Posted: 19 Jul 2023 08:31
by koko
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.
Re: Deleting but with sending items to Recycle Bin
Posted: 19 Jul 2023 10:09
by DOSadnie
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?
Re: Deleting but with sending items to Recycle Bin
Posted: 19 Jul 2023 10:44
by DOSadnie
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
Re: Deleting but with sending items to Recycle Bin
Posted: 19 Jul 2023 11:56
by koko
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.
Re: Deleting but with sending items to Recycle Bin
Posted: 19 Jul 2023 12:06
by npocmaka_
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
Re: Deleting but with sending items to Recycle Bin
Posted: 24 Jul 2023 02:33
by Batcher
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()"
Re: Deleting but with sending items to Recycle Bin
Posted: 24 Jul 2023 14:49
by DOSadnie
I tested this java script out and it works. Unfortunately I have failed at such basic reworking of it as applying it to
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