Can the SWIN CommonDialog.openFilename() method be used to select
multiple filenames at one time?
Thanks,
–Alex DeCaria
Can the SWIN CommonDialog.openFilename() method be used to select
multiple filenames at one time?
Thanks,
–Alex DeCaria
On Feb 11, 10:32 am, Alex DeCaria [email protected]
wrote:
Can the SWIN CommonDialog.openFilename() method be used to select
multiple filenames at one time?
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 H. wrote:
On Feb 11, 10:32�am, Alex DeCaria [email protected]
wrote:Can the SWIN CommonDialog.openFilename() method be used to select
multiple filenames at one time?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 outcheers
Chris
I’m also trying to figure this out. The best I have so far is:
OFN_EXPLORER = 0x00080000
OFN_ALLOWMULTISELECT = 0x00000200
#(…)lots of other constants
require ‘swin’
filetype_filter = [[‘Ruby files (.rb)‘,’.rb’],
[‘All files (.)’, ‘.’]]
paths = SWin::CommonDialog::openFilename(
nil,
filetype_filter,
OFN_ALLOWMULTISELECT,
‘Choose one or more files.’)
puts paths
Which looks like a horrible blast from the past: windows 3.1!
It works, but the result looks like this:
“D:\projects\test\ autoit_test.rb binomial.rb”
And what if the filename contains a space? Ah yes, of course, short
filenames.
“D:\projects\test\ blum_blum_shub.rb BOYGIR~1.RB”
Another try:
paths = SWin::CommonDialog::openFilename(
nil,
filetype_filter,
OFN_EXPLORER| #<–let’s try this one
OFN_ALLOWMULTISELECT,
‘Choose one or more files.’)
puts paths
This looks better, but it doesn’t work. When multiple files are selected
I only get the directory back, none of the files.
Help appreciated,
Siep
Chris H. wrote:
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::openFilename( 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”
endusing 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 thisCheers
Chris: Thanks for your efforts. I copied and pasted your code, but no
matter how many files I select, files.length is coming out to be 1.
What happens is:
If I select a single file, then files contains the entire filename
including the path.
If I select multiple files, then files just contains the path, with
no filename.
The .split(NUL) method on paths doesn’t seem to work for me.
I am using Windows7 Professional (64-bit). I don’t know if this is
caused by a difference in OS?
–Alex
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::openFilename( 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 H. wrote:
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 goodHow 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
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
Alex DeCaria wrote:
Chris H. wrote:
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 goodHow 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 editorI’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
I forgot to mention that I’m running it from the Windows command line.
Also, I just tried it on a different system with Windows XP Professional
and got the same result (files.length = 1) regardless of how many files
I select.
Chris H. wrote:
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 goodHow 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: I downloaded and unzipped vrswin090207. I also downloaded and
unzipped the DevKit into my C:\Ruby directory. I don’t know what to do
next (I’ve never used DevKit. Can you tell me what to do next inorder
to build and install SWIN?
–Alex
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
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
On Feb 17, 2:44 pm, Alex DeCaria [email protected]
wrote:
–Alex
Posted viahttp://www.ruby-forum.com/.
Lookig at the swin code I think the 6th argument is the initial dir,
so try this:
SWin::CommonDialog::openFilename( nil, filetype_filter,
OFN_EXPLORER|OFN_ALLOWMULTISELECT, ‘Choose one or more files.’,nil,“C:
\some\path”)
Chris H. wrote:
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 thatcheers
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs