Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kill "filename.ext" = shift-delete
#1
It would be real nice to have a version of kill not bypassing the recycle bin.  Maybe _kill "filename.ext" ?

To recover an accidental deleted file I had to use a third party recovery program.  Need a safer way to delete a file.

Thanks
Reply
#2
(02-21-2026, 02:14 PM)doppler Wrote: It would be real nice to have a version of kill not bypassing the recycle bin.  Maybe _kill "filename.ext" ?

To recover an accidental deleted file I had to use a third party recovery program.  Need a safer way to delete a file.

Thanks

When I think I may need a file again after deleting it, I use Name "FileName" As (temporary filename). Works for me. If I "kill" a file I expect it to die, but sometimes I like to keep the defib tool handy.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#3
(02-21-2026, 02:14 PM)doppler Wrote: It would be real nice to have a version of kill not bypassing the recycle bin.  Maybe _kill "filename.ext" ?

To recover an accidental deleted file I had to use a third party recovery program.  Need a safer way to delete a file.

Thanks

   Do you need this to be cross platform or just one OS ?
Reply
#4
Make Sub or Function to Move file to Recycle Bin.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#5
(02-21-2026, 11:09 PM)bplus Wrote: Make Sub or Function to Move file to Recycle Bin.

    Just a move would work.   But that doesn't preserve the correct restore path.   Windows and Linux both have an API to send something to the Recycle bin
and preserve the proper restore path !    I've been trying to figure out a Cross Platform SUB to do what the OP wants.   If it's Windows or Linux ONLY would be
a lot easier !
Reply
#6
If you're using Windows, Spriggsy had a method he included in a demo, which I slightly modified that worked perfectly for me; unfortunately I cannot remember the name of my program I adapted it to.

However.... Here is Spriggy's code. Be careful and test it on something you don't care about or a junk file you created. I can't be positive, but I think this is the only one I have, and whatever program I modified it to work in, worked. At least I can still remember that much from 4 years ago.

Pete

Code: (Select All)
'$CONSOLE:ONLY
'_DEST _CONSOLE

'To - From, From - To Flags
Const FO_MOVE = &H1
Const FO_COPY = &H2
Const FO_DELETE = &H3
Const FO_RENAME = &H4

'File Op Flags
Const FOF_MULTIDESTFILES = &H1
Const FOF_CONFIRMMOUSE = &H2
Const FOF_SILENT = &H4
Const FOF_RENAMEONCOLLISION = &H8
Const FOF_NOCONFIRMATION = &H10
Const FOF_WANTMAPPINGHANDLE = &H20
Const FOF_ALLOWUNDO = &H40
Const FOF_FILESONLY = &H80
Const FOF_SIMPLEPROGRESS = &H100
Const FOF_NOCONFIRMMKDIR = &H200
Const FOF_NOERRORUI = &H400
Const FOF_NOCOPYSECURITYATTRIBS = &H800
Const FOF_NORECURSION = &H1000
Const FOF_NO_CONNECTED_ELEMENTS = &H2000
Const FOF_WANTNUKEWARNING = &H4000
Const FOF_NORECURSEREPARSE = &H8000
Const FOF_NO_UI = FOF_SILENT

'Return Values
Const DE_SAMEFILE = &H71
Const DE_MANYSRC1DEST = &H72
Const DE_DIFFDIR = &H73
Const DE_ROOTDIR = &H74
Const DE_OPCANCELLED = &H75
Const DE_DESTSUBTREE = &H76
Const DE_ACCESSDENIEDSRC = &H78
Const DE_PATHTOODEEP = &H79
Const DE_MANYDEST = &H7A
Const DE_INVALIDFILES = &H7C
Const DE_DESTSAMETREE = &H7D
Const DE_FLDDESTISFILE = &H7E
Const DE_FILEDESTISFLD = &H80
Const DE_FILENAMETOOLONG = &H81
Const DE_DEST_IS_CDROM = &H82
Const DE_DEST_IS_DVD = &H83
Const DE_DEST_IS_CDRECORD = &H84
Const DE_FILE_TOO_LARGE = &H85
Const DE_SRC_IS_CDROM = &H86
Const DE_SRC_IS_DVD = &H87
Const DE_SRC_IS_CDRECORD = &H88
Const DE_ERROR_MAX = &HB7
Const UNKNOWN = &H402
Const ERRORONDEST = &H10000
Const DE_ROOTDIR_ERRORONDEST = &H10074

Type SHFILEOPSTRUCTA
    hwnd As _Offset
    $If 64BIT Then
        wfunc As _Unsigned _Integer64 'To - From, From - To Flags
    $Else
    wfunc AS _UNSIGNED LONG
    $End If
    pFrom As _Offset
    pTo As _Offset
    fFlags As Long
    fAnyOperationsAborted As _Byte
    hNameMappings As _Offset
    lpszProgressTitle As _Offset
End Type

Type SHQUERYRBINFO
    $If 64BIT Then
        cbsize As _Integer64
        i64Size As _Integer64
        i64NumItems As _Integer64
    $Else
    cbsize AS LONG
    i64Size AS _INTEGER64
    i64NumItems AS _INTEGER64
    $End If
End Type

Declare Dynamic Library "Shell32"
    Function FileOperation% Alias SHFileOperationA (lpFileOp As SHFILEOPSTRUCTA)
    Function EmptyRecycleBin% Alias SHEmptyRecycleBinA (ByVal hwnd As Long, ByVal pszRootPath As _Offset, ByVal dwFlags As Long)
    Function QueryRecycleBin~& Alias SHQueryRecycleBinA (pszRootPath As String, pSHQueryRBInfo As SHQUERYRBINFO)
End Declare

'Test code
If _FileExists(_Dir$("desktop") + "this is a test.txt") = 0 Then
    Open _Dir$("desktop") + "this is a test.txt" For Output As #1
    Close #1
End If
Print Copy(_Dir$("desktop") + "this is a test.txt", _Dir$("desktop") + "this is a test as well.txt")
_Delay 2
Print Rename(_Dir$("desktop") + "this is a test as well.txt", _Dir$("desktop") + "this is a test also.txt")
_Delay 2
Print Recycle(_Dir$("desktop") + "this is a test also.txt")
_Delay 2
Print GetRecycleInfo
_Delay 2
Print EmptyBin


Function GetRecycleInfo$
    Dim RecycleInfo As SHQUERYRBINFO
    Dim path As String
    Dim a~&
    path = "" + Chr$(0)
    RecycleInfo.cbsize = Len(RecycleInfo)
    a~& = QueryRecycleBin(path, RecycleInfo)
    GetRecycleInfo = _Trim$(Str$(RecycleInfo.i64Size)) + " " + _Trim$(Str$(RecycleInfo.i64NumItems))
End Function

Function Recycle% (file As String)
    Dim lpFileOp As SHFILEOPSTRUCTA
    Dim doublenull As String
    doublenull = Chr$(0) + Chr$(0)
    file = file + doublenull
    lpFileOp.hwnd = _WindowHandle
    lpFileOp.wfunc = FO_DELETE
    lpFileOp.pFrom = _Offset(file)
    lpFileOp.fFlags = FOF_ALLOWUNDO + FOF_WANTNUKEWARNING
    Recycle = FileOperation(lpFileOp)
End Function

Function Copy% (file As String, dest As String)
    Dim lpFileOp As SHFILEOPSTRUCTA
    Dim doublenull As String
    doublenull = Chr$(0) + Chr$(0)
    file = file + doublenull
    dest = dest + doublenull
    lpFileOp.hwnd = _WindowHandle
    lpFileOp.wfunc = FO_COPY
    lpFileOp.pFrom = _Offset(file)
    lpFileOp.pTo = _Offset(dest)
    lpFileOp.fFlags = FOF_ALLOWUNDO
    Copy = FileOperation(lpFileOp)
End Function

Function Move% (file As String, dest As String)
    Dim lpFileOp As SHFILEOPSTRUCTA
    Dim doublenull As String
    doublenull = Chr$(0) + Chr$(0)
    file = file + doublenull
    dest = dest + doublenull
    lpFileOp.hwnd = _WindowHandle
    lpFileOp.wfunc = FO_MOVE
    lpFileOp.pFrom = _Offset(file)
    lpFileOp.pTo = _Offset(dest)
    lpFileOp.fFlags = FOF_ALLOWUNDO
    Move = FileOperation(lpFileOp)
End Function

Function Rename% (file As String, newname As String)
    Dim lpFileOp As SHFILEOPSTRUCTA
    Dim doublenull As String
    doublenull = Chr$(0) + Chr$(0)
    file = file + doublenull
    newname = newname + doublenull
    lpFileOp.hwnd = _WindowHandle
    lpFileOp.wfunc = FO_RENAME
    lpFileOp.pFrom = _Offset(file)
    lpFileOp.pTo = _Offset(newname)
    lpFileOp.fFlags = FOF_ALLOWUNDO
    Rename = FileOperation(lpFileOp)
End Function

Function EmptyBin%
    Dim drive As String
    drive = ""
    EmptyBin = EmptyRecycleBin(0, _Offset(drive), 0)
End Function
Reply
#7
Nice, Pete. I was going to suggest the Recycle Bin code to doppler and I scrolled down to see you've already shared it. Thanks!
The noticing will continue
Reply
#8
If any Linux or Mac peeps want to share the equivalent code for their respective platforms, we'll have a cross-platform solution!  Smile
Reply
#9
I would also like to quickly add that KILL should only be used for files that you are creating and using within your code. I would never use KILL to delete files outside of the code space.
The noticing will continue
Reply
#10
(02-27-2026, 06:03 PM)SpriggsySpriggs Wrote: I would also like to quickly add that KILL should only be used for files that you are creating and using within your code. I would never use KILL to delete files outside of the code space.

     Hold my Beer !   


     rofl......
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Shift key not recognized when focus is changed to QB64 program dano 17 2,998 09-18-2024, 03:15 AM
Last Post: TerryRitchie

Forum Jump:


Users browsing this thread: