Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kill "filename.ext" = shift-delete
#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


Messages In This Thread
kill "filename.ext" = shift-delete - by doppler - 02-21-2026, 02:14 PM
RE: kill "filename.ext" = shift-delete - by bplus - 02-21-2026, 11:09 PM
RE: kill "filename.ext" = shift-delete - by Pete - 02-22-2026, 08:53 PM

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: 1 Guest(s)