Code: (Select All)
Screen _NewImage(800, 600, 32)
Open "MyFile.txt" For Output As #1
Print #1, "Test:" + Date$ + " " + Time$
Close
Print "File created called MyFile.txt"
Recycle "MyFile.txt"
Print "MyFile.txt should now be recycled and in the Recycle Bin, instead of just erased permanently."
Print "Check your recycle bin to see if it exists there and contains a simple message of 'Test'."
End
Sub Recycle (file$)
If _FileExists(file$) Then
$If WIN Then
ps$ = "powershell -NoLogo -NoProfile -Command "
ps$ = ps$ + Chr$(34) + "Add-Type -AssemblyName Microsoft.VisualBasic; "
ps$ = ps$ + "[Microsoft.VisualBasic.FileIO.FileSystem]:eleteFile('"
ps$ = ps$ + file$
ps$ = ps$ + "','OnlyErrorDialogs','SendToRecycleBin')" + Chr$(34)
Shell _Hide ps$
$ElseIf MAC Then
Shell _Hide "mv " + Chr$(34) + file$ + Chr$(34) + " ~/.Trash/"
If _FileExists(file$) Then 'a back up second method as per here --> https://www.macterminal.cc/answers/mv-command-examples
message$ = "File failed to move to trash folder. Possible reasons for this are:" + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "1. Missing Full Disk Access" + Chr$(10)
message$ = message$ + "By default, the Terminal does not have permission to modify 'protected' folders like ~/.Trash/, leading to 'Operation not permitted' errors. "
message$ = message$ + Chr$(10)
message$ = message$ + "Fix: Go to System Settings > Privacy & Security > Full Disk Access and toggle the switch for Terminal to ON." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "2. Incorrect Trash Path for External Drives" + Chr$(10)
message$ = message$ + "Each drive on a Mac has its own hidden trash folder. If the file you are moving is on an external drive, ~/.Trash/ (which is on your internal startup disk) might not be the correct destination for a simple 'move'." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "Fix: For files on external volumes, the path is usually /Volumes/[DriveName]/.Trashes/[UserUID]/." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "3. Folder Ownership or Corruption" + Chr$(10)
message$ = message$ + "Sometimes the .Trash directory itself has incorrect permissions or has become corrupted." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "Verify: Run ls -ld ~/.Trash to see the permissions. It should be owned by your username with rwx permissions." + Chr$(10)
message$ = message$ + "Fix: If it's missing or broken, you can recreate it by running mkdir ~/.Trash (though you may need to delete a corrupted one first with sudo rm -rf ~/.Trash)." + Chr$(10)
_MessageBox "File failed to move to trash", message$, "info"
End If
$Else
'Assume Linux-like environment with gio available
SHELL _HIDE "gio trash " + CHR$(34) + file$ + CHR$(34)
$End If
End If
End Sub
A simple routine which should send a file to the recycle bin, rather than just destroy it utterly like it does with KILL or a shell to DEL or ERASE. Short, simple, and easy enough to toss into any program which needs to make use of it, without a lot of dependencies and such attached to working with it.
Edit: Updated to hopefully work on Mac and Linux. At least according to others who use Mac and Linux, *they* claim this works. I'm a windows guy myself, so I'm just trusting them. I can't actually test it on my own to be certain, so try it out and if it fails, fuss at them!
:D


in the middle of the code box of text! LOL!! If anyone grabbed it and tried it and it failed to work, try it again now that the letters are letters and not big smiling faces in the middle of the code.
