3

Possible Duplicate:
Enable dropping a file onto a Ruby script

I would like to have ruby open with dropped files as arguments. I running Win 7 Enterprise, Ruby 1.8.6 and have tried RubyDragAndDrop.dll, which I could not get installed. Any ideas?

Community
  • 1
  • 1
Myddraall
  • 103
  • 1
  • 9
  • @Andrew barber, if you look at both questions you should realize they are NOT DUPLICATES, the question here is specific windows with my answer being a windows answer, the other question is cross platform, i posted my answer there as a reference. I therefore find it necessary this answer question/answer to revice – peter just now edit – peter Apr 22 '14 at 11:11

1 Answers1

3

One alternative is to create a batch file that handles the drag and drop part. As seen here, when you drag and drop files onto a batch file, the list of dropped files will be stored in %* as a space-separated list. A batch file that simply said ruby yourscript.rb %* should take this list of files and pass it to your script (where you can access the arguments using the ARGS array).

Community
  • 1
  • 1
bta
  • 43,959
  • 6
  • 69
  • 99
  • 1
    The problem with this is that if you drag a file from a folder different than the folder containing the ruby file, you get linking errors, as it tries to run the script with the working directory for the file dragged, not the file run. I.E. A file on the desktop, file1, is dragged into a bat file in a folder, Folder1. the bat file calls a ruby script in Folder1. The pwd (as written to the prompt from the bat file) is the desktop, even though the bat file lives in Folder1. Is there a way to get the file to run from the bat file's folder? – Myddraall Aug 02 '10 at 20:03
  • Before launching the Ruby script, add a line that does a `cd` to the folder containing the .bat file (use an absolute path). – bta Aug 02 '10 at 20:43
  • This worked, a caution though; before I tried to use a bat file, I tried a c++ app that just called system and passed in the args as a string. I couldn't get that to work even using cd. I don't know if that was user error, but the bat worked with cd. Thank you. – Myddraall Aug 03 '10 at 13:34