views:

27

answers:

1

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?

A: 

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).

bta
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
Before launching the Ruby script, add a line that does a `cd` to the folder containing the .bat file (use an absolute path).
bta
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