Windows recycle API call?

D

daz

Chris said:
Anyone got a Rubied call to the Windows API for recycling a file handy?

http://msdn.microsoft.com/library/e...shell/reference/structures/shfileopstruct.asp
(FO_DELETE with FOF_ALLOWUNDO, I believe will do the trick...)


# Windows only script
require 'Win32API'

FO_DELETE = 3

FOF_NOCONFIRMATION = 16
FOF_ALLOWUNDO = 64

SHFileOperation = Win32API.new('shell32', 'SHFileOperation', 'P', 'I')

def recycle(fname, confirm = FOF_NOCONFIRMATION)
fnp = fname.to_s << "\0\0"
confirm = 0 unless confirm == FOF_NOCONFIRMATION
shfos = [
0, FO_DELETE, fnp, 0, FOF_ALLOWUNDO | confirm, 0, 0, 0
].pack('LLpLLLLL')
SHFileOperation.call(shfos)==0 ? true : false
end

#--------------------

filename = 'C:\TEMP\to_be_recycled.txt'

File.open(filename, 'w') do |fo|
fo.puts 'to_be_rescued'
end

#--------------------

ret = recycle(filename, :r_u_sure)
p ret ? 'OK' : 'failed'


daz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top