From: daz Date: 2004-05-08T05:33:56+09:00 Subject: Re: Windows recycle API call? Chris Morris wrote: > Anyone got a Rubied call to the Windows API for recycling a file handy? > > http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/structures/shfileopstruct.asp > (FO_DELETE with FOF_ALLOWUNDO, I believe will do the trick...) > > -- > Chris > http://clabs.org > # 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