News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Delete file

Started by Grincheux, October 08, 2008, 11:16:18 AM

Previous topic - Next topic

Grincheux

I would like how to know for deleting a file and be able to rerieve it from the dustbin.
Usually I use DeleteFile but with this function the file is lost...

How can I do ?
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

n00b!

Use SHFileOperation with an adequate SHFILEOPSTRUCT.

QuoteWhen used to delete a file, SHFileOperation permanently deletes the file unless you set the FOF_ALLOWUNDO flag in the fFlags  member of the SHFILEOPSTRUCT structure pointed to by lpFileOp. Setting that flag sends the file to the Recycle Bin. If you want to simply delete a file and guarantee that it is not placed in the Recycle Bin, use DeleteFile.

ragdog

Hi

I have only this found  i Hope it help you.



; recycle.asm written by Hutch

.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
include \masm32\macros\macros.asm

RecycleFile PROTO :DWORD

;


.data

fname1 db "c:\_recyclefiletest.000",0
fname2 db "c:\_recyclefiletest.001",0,0

buffer db 30 dup (0)

.code

;

start:
; create two 0 byte files
invoke CreateFile,ADDR fname1,
GENERIC_READ,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
invoke CloseHandle,eax
test eax, eax
jnz @F
print SADD("CloseHandle failed")
@@:
invoke CreateFile,ADDR fname2,
GENERIC_READ,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
invoke CloseHandle,eax
test eax, eax
jnz @F
print SADD("CloseHandle failed")
@@:

invoke RecycleFile,ADDR fname1

push eax
invoke GetLastError
invoke dw2a,eax,ADDR buffer ; what is this doing ?
print SADD(13,10,"GetLastError returned ") ; print macro
print ADDR buffer
pop eax
invoke dw2a,eax,ADDR buffer
print SADD(13,10,"RecycleFile returned ")
print ADDR buffer

print SADD(13,10,"Press enter to exit...",13,10)
invoke StdIn,ADDR buffer,1
exit


; This proc calls the SHFileOperation function to delete
; the specified file or files to the recycle bin. Each file
; must be specified with a fully qualified path (otherwise,
; the file will simply be deleted, without being placed in
; the recycle bin). Multiple files can specified by
; separating the individual paths with a null, and appending
; an additional null to the end of the final path.
;
; Returns zero for success, or nonzero for failure.
;
; Initializing the hwnd element to NULL proved to be
; necessary so the SHFileOperation function could delete
; a file that was created by the calling process.
;

RecycleFile proc pszFullPath:DWORD
LOCAL fo:SHFILEOPSTRUCT

mov fo.hwnd, NULL
mov fo.wFunc, FO_DELETE
m2m fo.pFrom, pszFullPath
mov fo.pTo, NULL
mov fo.fFlags,FOF_ALLOWUNDO
invoke SHFileOperation,ADDR fo

ret
RecycleFile endp

end start

Grincheux

Thank you for this. I did not thought to 'SHFileOperation' !
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz