plendid has asked for the wisdom of the Perl Monks concerning the following question:

Hello, this is my first Perl Monks post.

I'm writing a script that will take one or more Excel spreadsheets and use their data to update Oracle data. I'm able to call the requisite Windows open file dialog but i can't seem to then get the dialog box to accept more than one file. Please advise,

$fileDialogParameters{title} and $fileDialogParameters{dir} behave as expected. So i know the call is working. It seems however that $fileDialogParameters{options} gets ignored. Also i would think that i should be able to enter multiple options (for example OFN_ALLOWMULTISELECT and OFN_EXPLORER) but i have no idea how to do this either

use Win32::FileOp; $fileDialogParameters{title} = q(Open quota spreadsheet(s)); $fileDialogParameters{dir} = q(c:\\); $fileDialogParameters{options} = $OFN_ALLOWMULTISELECT; #also tried OF +N_ALLOWMULTISELECT @fileName = OpenDialog \%fileDialogParameters;

Win32::FileOp doc = http://interglacial.com/~sburke/tpj/as_html/tpj21.html

Thanks.

Replies are listed 'Best First'.
Re: Using Win32::FileOp::OpenDialog to get multiple files
by BrowserUk (Patriarch) on Sep 17, 2008 at 16:40 UTC

    With the addition of a pass-all filter, your code works for me:

    #! perl -slw use strict; use Win32::FileOp; my %fileDialogParameters; $fileDialogParameters{title} = q(Open quota spreadsheet(s)); $fileDialogParameters{dir} = q(c:\\); $fileDialogParameters{options} = OFN_ALLOWMULTISELECT; ## Note: No '$' $fileDialogParameters{filters} = [ All files => '*' ]; my @fileName = OpenDialog \%fileDialogParameters; print "@fileName"; __END__ C:\test>junk1 C:\.q_history C:\autoexec.bat C:\CONFIG.SYS C:\dodmd.cmd

    You can actually achieve the same thing (the display of filenames to select from), without specifying a filter, by typing '*' in the filename field and clicking ok.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Using Win32::FileOp::OpenDialog to get multiple files
by Sagacity (Monk) on Sep 17, 2008 at 16:29 UTC

    It appears that the behavior of the dialog is suffering from buffering.

    This is what I found on CPAN at Win32::fileOp.

    "There is a little problem with the underlying function. You have to preallocate a buffer for the selected filenames and if the buffer is too small you will not get any results. I've consulted this with the guys on Perl-Win32-Users and there is not any nice solution. The default size of buffer is 256B if the options do not include OFN_ALLOWMULTISELECT and 64KB if they do. You may change the later via variable $Win32::FileOp::BufferSize."

    Set your buffering to 128KB before you attempt to use the dialog. Step up your buffer size until you get the results you are seeking.

    Slow down and read the guidance offered on the CPAN.

    Good luck!

    UPDATE: BrowserUk set the filter '*', which forced an allocation for the filter buffer (and eased the suffering from buffering). This approach forces the OS to handle the buffer allocation; However, you may want to modify the filter to '*.xls', '*.*' or some other value as a literal. No sense in wasting resources on file types you don't need.