Hi Monks!

I am struggling with the following piece of code. My need: selecting a directory (possibly with UTF characters) and save a text file. This piece of code creates a folder and put inside it the file. How can I prevent the creation of the folder (this is the part I found on the web)? I just took away the "unless" part of the code, but if doing so, the script is no longer able to write in a folder with UTF characters! What am I missing? Thanks. Cla

use Tk; use strict; use warnings; use Encode qw( encode ); use File::Slurp; use File::Spec::Functions qw( catfile ); use Win32; use Win32::API; use constant ERROR_ALREADY_EXISTS => 0xb7; my $mw = MainWindow->new; $mw->title('Menu'); my $menubar = $mw->Menu(-type => 'menubar'); $mw->configure(-menu => $menubar); my $mfile = $menubar->cascade(-label => '~File', -tearoff => 0); $mfile->command(-label => '~Save', -command => \&save_file4); my $exit = $mw->Button(-text => 'Exit', -command => [$mw => 'destroy']); $exit->pack; my $types = [ ['HTML files', '.txt'], ['All Files', '*'],]; MainLoop; sub save_file4 { my $save = $mw->getSaveFile(-filetypes => $types, -initialfile => 'test', -defaultextension => '.txt'); unless ( Win32::CreateDirectory($save) ) { my $err = $^E; if ( $err == ERROR_ALREADY_EXISTS ) { warn "Directory exists, no problem\n"; } else { die Win32::FormatMessage($^E); } } my $ansi_path = Win32::GetANSIPathName($save); warn "$ansi_path\n"; my $file = catfile($ansi_path, 'test.txt'); open(OUT,">$file") or die $!; print OUT $file; close OUT; }

In reply to path encoding folder by fanticla

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.