Hi Monks. I have a perl tk widget that i am trying to get to copy a file to a previous version. But for some reason it does all i want except copy the file. the directory and file both exist. I can do an open both files successfuly!
error message Tk::Error: Unable to open file: No such file or directory at C:\Users\ +aaaa.pl line 63. main::resthand at C:\Users\aaaa.pl line 63 Tk callback for .labframe.border.frame1.button Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 251 Tk::Button::butUp at C:/Perl/site/lib/Tk/Button.pm line 175 <ButtonRelease-1> (command bound to event)
perl script
#!/usr/bin/perl use strict; use warnings; use File::Path qw( mkpath); use File::Copy qw(copy); use File::Copy qw(move); use Tk; use Tk::BrowseEntry; use Tk::LabFrame; use Tk::LabEntry; use Tk::Widget; my $test_bak = "G:\\temp\\Hand"; my @restore_files; opendir (DIR, $test_bak) or warn $!; while (my $restore_bak = readdir(DIR)) { push (@restore_files, "$restore_bak\n"); } closedir(DIR); my $restore_date = ''; my $mw = MainWindow->new(-title => " test ", -background =>'LightBlue2',-foreground=>'DarkBlue'); $mw->geometry("450x240"); #--------------------------------------------------------------------- +--------------------------------------- # create frames labels and buttons # #--------------------------------------------------------------------- +--------------------------------------- my $frame = $mw->LabFrame(-font => 'Times 08',-background =>'Light +Blue2', -labelside => "acrosstop",-foreground =>'Slategray +') ->pack(-side => 'top'); my $rest_sel = $frame ->BrowseEntry(-label => 'Select restore date + : ', -foreground=>'DarkBlue', -background =>'LightBlue2', -textvariable=> \$rest +ore_date) ->grid(-sticky => 'w', -column => 2, -row => 1 ); $rest_sel -> insert('end', @restore_files); my $restspace = $frame->Label(-text => ' ',-background =>'L +ightBlue2') ->grid(-sticky => 'e', -column => 4, -row => 1 ); my $restore_but = $frame -> Button(-text => " Restore ", -command +=>[\&resthand], -foreground=>'DarkBlue', -relief => 'raised', -background =>'LightBlue2', - +activebackground =>'DodgerBlue1' )->grid(-sticky => 'e', -column => 5, -row => 1 ); + my $textframe = $mw->Scrolled("Text", -scrollbars => 'e', -foregro +und=>'Green',-background => "Black", -height => 12) ->pack(-side => 'bottom', -fill => +'both'); tie *STDOUT, 'Tk::Text', $textframe; MainLoop; sub resthand { $|++; $textframe->delete("1.0", 'end'); printf " Restoring version $restore_date \n"; my $restore_to = "G:/temp/Hand/Hand.pl"; my $replace = "G:/temp/Hand/"; my $rest_string = join( "", "$replace", "$restore_date" ); print "$rest_string \n"; # check filehandles print "$restore_to \n"; copy ($rest_string, $restore_to) or die "Unable to + open file: $!"; $textframe->see('end'); }

In reply to perl tk widget will not copy files by john.tm

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.