A
Alex DeCaria
Can the SWIN CommonDialog.openFilename() method be used to select
multiple filenames at one time?
Thanks,
--Alex DeCaria
multiple filenames at one time?
Thanks,
--Alex DeCaria
Can the SWIN CommonDialog.openFilename() method be used to select
multiple filenames at one time?
Chris said:Had to look at the code but looks like it is a straight forward
wrapper of the CommonDialog:GetOpenFileName (http://msdn.microsoft.com/
en-us/library/ms646829(VS.85).aspx#open_file)
so supports all its functionality
Set the OFN_ALLOWMULTISELECT flag, and the result should be a string
containing all the files.
The windows doc says it could be NULL separated or space separated so
you'll need to play a bit to figure out
how to parse out the individual file names.
This is all based on reading, so while in theory its correct, in
practice you'll have to figure some stuff out
cheers
Chris
Chris said:I was able to get your code to work, surprisingly the docs seem to
actually be correct
Here is your (Siep) code expanded a bit:
require 'swin'
OFN_ALLOWMULTISELECT = 0x200
OFN_EXPLORER = 0x80000
NUL = "\x00"
filetype_filter = [['Ruby files (*.rb)','*.rb'],['All files (*.*)',
'*.*']]
paths = SWin::CommonDialog:penFilename( nil, filetype_filter,
OFN_EXPLORER|OFN_ALLOWMULTISELECT, 'Choose one or more files.')
if paths
files = paths.split(NUL)
if files.length > 1
puts "Found #{files.length-1} files in #{files[0]}"
files[1..-1].each_with_index{|el,i| puts "#{i} => #{el}"}
else
d,f = File.split(files[0])
puts "Single file: #{f} in #{d}"
end
else
puts "No selction made"
end
using OFN_EXPLORER returns the list of files as a string will NUL
separating the file names, allowing file names to contain spaces. The
directory is the first item in this case
If a single file is selected, the result is a single string with the
full path and file name.
Selecting cancel in the dialog results in a nul return value.
I have to thank Louis Laverna for his work on the new Ruby installer,
and epecially the dev kit that allowed me to build and install swin to
play with this
Cheers
Chris said:I installed the latest Ruby 1.9 via RubyInstaller.org
Installed the devkit from there as well
Downloaded swin (vrswin090207.zip) and built/installed it (Yeah!
devkit)
Ran it on a Win7 Home 64bit and it was good
How are you getting swin?
Are you running in an editor/IDE or from the command line?
It worked from me both from the command line and from the Komodo Edit
5.0 editor
Alex said:I'm running Ruby v.1.8.6 that I installed using the Windows 1-click
installer. I'm using whatever version of SWIN came with that install
package. I'll try to update SWIN and try again. Maybe I'll even
upgrade to Ruby 1.9.
Thanks. --Alex
Chris said:I installed the latest Ruby 1.9 via RubyInstaller.org
Installed the devkit from there as well
Downloaded swin (vrswin090207.zip) and built/installed it (Yeah!
devkit)
Ran it on a Win7 Home 64bit and it was good
How are you getting swin?
Are you running in an editor/IDE or from the command line?
It worked from me both from the command line and from the Komodo Edit
5.0 editor
Chris said:I followed the instructions in install.txt and it Just Worked!
Well the compile threw a bunch of warnings and the ended with a
message
about an error... but I was able to run the code for the dialog so I
think you
can ignore that
cheers
Chris:
SUCCESS! I installed Ruby 1.9 and vrswin090207, and your code works as
advertised. Apparently it can't be done with Ruby 1.8 and/or the older
version of vrswin.
One final question. Do you know how I can have the FileDialog open to a
predetermined directory, instead of the directory where the program is
started? That's the last key to my puzzle. I tried using a
Dir.chdir(mydirectory), but that didn't seem to work.
--Alex
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.