in reply to Best/Fast/Simple way to add a GUI to a batch process

If simple dialog windows to choose the files and present Yes or No kinds of questions would work then the following is pretty quick and easy. Instead of choosing an output file this uses a Save As dialog to input the file name. You could write to a temporary file and then copy to the file named in the Save As dialog when finished.

use strict; use warnings; use Win32::GUI(); use Win32; use Win32::FileOp qw(SaveAsDialog); my $startdir = 'C:\Users'; my $filename = Win32::GUI::GetOpenFileName( -title => 'Select a file' +, -directory => $startdir, -filter => ["Perl scripts (*.pl, *.pm)" => "*.pl;*.pm", "All files +" => "*.*", ],); if ($filename) { my $returnvalue = Win32::MsgBox("Use $filename ?",4,"Use it?"); if ($returnvalue == 6){ Win32::MsgBox("Using $filename as input."); } else{ Win32::MsgBox("Not using $filename as input."); } print "--- $filename\n"; } else { print "\$filename was not chosen by Win32::GUI::GetOpenfilename\n" +; exit; } my %parameters = ( title => "Output file", filters => {'Filter 1' => '*.txt;*.log', 'Filter 2' => '*.dat'}, filename => 'output.txt', ); my $output_file = SaveAsDialog %parameters , "output.txt"; if($output_file){ Win32::MsgBox("Using $output_file as output."); } else{ Win32::MsgBox("No output file chosen."); }

Replies are listed 'Best First'.
Re^2: Best/Fast/Simple way to add a GUI to a batch process
by vitoco (Hermit) on Aug 28, 2018 at 11:04 UTC

    To try this example, I had to install Win32, Win32::GUI and Win32::FileOp, but the last one failed like in Win32::FileOp issues and aborted. Argh!!!! Any hint? It seems that this module is not maintained anymore (Anyone wants to take over Win32::FileOp?).

    I'm thinking about to remove x64 version of Starwberry Perl from my Win10 machine and replace it with the 32 bits one...

      You can replace the Win32::FileOp part with the code below. I used several modules from whatever example code I found and quickly copy/pasted into my (Edit: original) reply. It was intended to show that there are a few options out there.

      I tested this on 64 bit Strawberry Perl. (Edit: My previous post was tested on 32 bit Strawberry Perl.)

      use strict; use warnings; use Win32::GUI(); my $startdir = 'C:\Users'; my $output_file = Win32::GUI::GetSaveFileName( -title => "Save as...", -directory => $startdir, -file => "output.txt", -filter => [ "Text documents (*.txt)" , "*.txt", "All files" , "*.*", ], ); if($output_file){ print("Using $output_file as output."); } else{ print("No output file chosen."); }

      I noticed that after I ran it once and chose a user directory it went to that same directory the next time. I assume it's a feature that it remembers. I found an option that seems to disable this kind of thing but haven't tried it. -nochangedir is 0 by default. It seems to be more to prevent the directory changing during the run so I'm surprised that the directory is remembered on the next run. Refer to http://perl-win32-gui.sourceforge.net/cgi-bin/docs.cgi?doc=Reference-Methods for more detail and other options.

      "I'm thinking about to remove x64 version of Starwberry Perl from my Win10 machine and replace it with the 32 bits one..."

      Re^4: Win32::FileOp issues includes "I'm using 32bit perl".

        Mmmmm... Win32:FileOp was installed OK in a 32 bit WinXP virtual machine, and then the full example worked as expected.

        Then I packed it into an EXE using PAR, and try this in the same WinXP VM successfully.

        Finally, I copied the EXE to my (other) Win10 x64 machine and run it there... Successfully!!! I was dissapointed. I was sure it would fail.

        I said "other" because this is the Win10 machine at my office that also has x64 Strawberry perl, but no GUI modules. I'll not try to install any of them here anyway. The original machine where I tried all the GUIs is at home ;-) I can't recall if both of them are the same or different editions of Win10, and I don't know if this matters!

        It seems that if I take the Win32::GUI way, I'll have to coninue the development on a 32 bit WinXP VM to get a running app in EXE format.