Perl::Tidy to the rescue.

Here's the code in a slightly more readable format. Will let other monks carry the torch from here:

#!/usr/bin/perl # Syntax : /../perl /.../PS_file_Rename.pl -s /..../Source_directory - +f filename.xls # .. -> path of Perl.exe # ... -> path of the script PS_file_Rename.pl # -s option - Source_Folder # -f option - Filename to use for renaming use Getopt::Std; use Data::Dumper; use POSIX qw(strftime); use vars qw($opt_s $opt_f); getopts('s:f:'); $ff = "$opt_s" . "\\" . "$opt_f"; #if the file name already exists delete it if ( -e $ff ) { unlink($ff) or warn scalar localtime( time() ), " WARN Can't delete $ff : $! +"; } my $path = $opt_s . "\\*.*"; $path =~ s|\\|/|g; #find the newest file my $newestfile = (sort {(stat $b)[10] <=> (stat $a)[10]} glob $path)[0 +]; #rename the newest file to the name passed rename( $newestfile, $ff ) or warn scalar localtime( time() ), " WARN Can't rename $newestfile +: $!"; @files = glob $opt_s . "\\*.*"; foreach my $file (@files) { if ( $file ne $ff ) { unlink($file) or warn scalar localtime( time() ), " WARN Can't delete " . $opt_s . "\\" . $file . " : $!"; } }

In reply to Re: Rename file by wind
in thread Rename file by sashawn

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.