API:
Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (Byval pFileOp As Dword) As Long
Thinbasic-function:
'######################################################################################################################
' recycles files and folders ( means to move those into the garbage-can )
'######################################################################################################################
function Recycle(byval sPath as string,
optional byval bNeed2Confirm as Boolean ) as boolean
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' sPath
' can be any { filename | directory | wildcard }-combination
' e.g., "C:\Data\*\R*me.txt"
' bNeed2Confirm
' if TRUE, a dialog will show up and ask the user to confirm the action alike
' "Do you really want to move the file xy into the recycling-bin ?" [YES] [NO]
' if FALSE, it is done silently without any sign of action
' returns:
' TRUE if succesful
' FALSE if failed (due to lack of privilege, read-only-media etc)
string szPath, sBuffer
Long l = 32
'......................................................................................................................
if rightf$(sPath, 1) = "\" then
szPath = Utf8ToAnsi$(leftf$(sPath,lenf(sPath)-1)) & $NUL
else
szPath = Utf8ToAnsi$(sPath) & $NUL
endif
while l < lenf(szPath)
l += l
wend
if lenf(szPath) < l then szPath &= repeat$(l - lenf(szPath), $NUL)
sBuffer = mkdwd$(0, 3, strptr(szPath), 0) & _
MKWRD$(iif(bNeed2Confirm, 64, 80)) & _
MKDWD$(0, 0, 0)
SHFileOperation( strptr(sBuffer) )
function = File_Exists(sPath) xor true
'......................................................................................................................
end function
'======================================================================================================================
Bookmarks