From: Alex DeCaria Date: 2010-02-13T20:34:57+09:00 Subject: Re: Can SWIN CommonDialog.openFilename() select multiple files? Chris Hulan 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" > 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: 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: 1) If I select a single file, then files contains the entire filename including the path. 2) 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 -- Posted via http://www.ruby-forum.com/.