Send to Recycle Bin: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Adding new author and category links.)
Line 1: Line 1:
{|align=right
{{PageAuthor|Iceman_K}}
|<small>Author: [[{{ns:2}}:Iceman_K|Iceman_K]] ([[{{ns:3}}:Iceman_K|talk]], [[{{ns:-1}}:Contributions/Iceman_K|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
Silently send a file/files/directory to the Windows Recycle bin instead of permanantly deleting it.
Silently send a file/files/directory to the Windows Recycle bin instead of permanantly deleting it.
Line 49: Line 47:
</highlight-nsis>
</highlight-nsis>


[[{{ns:14}}:Disk, Path & File Functions]]
[[Category:Disk, Path & File Functions]]

Revision as of 13:48, 24 June 2005

Author: Iceman_K (talk, contrib)


Description

Silently send a file/files/directory to the Windows Recycle bin instead of permanantly deleting it. This function supports standard windows wildcards. The return value is pushed on the stack. A non-zero value indicates an error.

Usage

Push "c:\temp\xyz.txt" ; File to delete, supports wildcards
Call SendToRecycleBin
Pop $R0 ; Return code

The Function

Include the following code in your nsi file:

!ifndef FO_DELETE
!define FO_DELETE 0x3
!endif
!ifndef FOF_SILENT
!define FOF_SILENT 0x4
!endif
!ifndef FOF_NOCONFIRMATION
!define FOF_NOCONFIRMATION 0x10
!endif
!ifndef FOF_ALLOWUNDO
!define FOF_ALLOWUNDO 0x40
!endif
 
Function SendToRecycleBin
Exch $R0
Push $R1
Push $R2
 
System::Alloc 28
Pop $R1
System::Call "*$R1(i $HWNDPARENT, i ${FO_DELETE}, t '$R0', t '', i ${FOF_ALLOWUNDO}|${FOF_SILENT}|${FOF_NOCONFIRMATION}, i 0, i 0, t '')"
System::Call "shell32::SHFileOperationA(i R1)i.R2"
System::Free $R1
StrCpy $R0 $R2
Pop $R2
Pop $R1
Exch $R0
FunctionEnd