Windows recycle API call?

Discussion in 'Ruby' started by Chris Morris, May 7, 2004.

  1. Chris Morris

    Chris Morris Guest

    Chris Morris, May 7, 2004
    #1
    1. Advertising

  2. Chris Morris

    daz Guest

    Chris Morris wrote:

    > 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...)
    >
    > --
    > 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
    daz, May 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luther Miller
    Replies:
    2
    Views:
    2,025
    Luther Miller
    Aug 27, 2003
  2. Mr 071

    Application recycle on error

    Mr 071, Nov 20, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    337
    Natty Gur
    Nov 23, 2003
  3. Sunil Menon
    Replies:
    0
    Views:
    438
    Sunil Menon
    Dec 11, 2003
  4. ringo
    Replies:
    4
    Views:
    519
    gerry
    Jan 16, 2004
  5. Replies:
    2
    Views:
    136
    bbiker
    Oct 25, 2007
Loading...

Share This Page