The problem is that you have forgotten the / after Xwords. It works fine if you add it.

my $dir = "c:/Xwords/"; my $from = '.puz'; my $to = 'A.puz'; while (<$dir*$from>) { my ($old,$new); $old = $new = $_; $new =~ s/$from$/$to/; rename $old, $new; }

The problem is that the * in the glob is rather like *.* in something like copy *.* a: - if the * matched everything you would not need the . there. In a glob the * will match a filename like 'foo.bar' but not a path/filename like '/foo.bar' Without the trailing / the glob <$dir*$from> is trying to match files in c:/ that match the filename /Xwords\w*.puz/ If you put a file in C:/ called Xwordstest.puz it will get renamed. In the original script the $dir was 'c:/' not 'c:', that is the difference and the problem.

A useful trick when a script does not work is to slip in some print statements to see what is going on. If you place a print in the while loop you will see that the while loop is never entered in your example.

Good to see you back.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Re: Re: File remaing and removal to a subdirectory by tachyon
in thread File renaming and removal to a subdirectory by Joes

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.