Question:
Can someone please direct me to the correct module to use and at least hints in the right direction to rename files in multiple directories using an array of hashes?

I'm new-ish to Perl, and haven't used Linux much. I made a script which runs on a VM (running Ubuntu) on a Windows OS. The script downloads a number of podcast subscriptions and deposits them in their respective directories.
I want to add some house-keeping functionality to it, specifically I want to have the script rename files in the downloaded folder according to regex patterns. I figured this would be easy, but I can't seem to get it to work right. Glob is not my friend.

I may later add deleting older files, but I want to do one part at a time. eg., I'm not sure how a perl function running on Linux will interpret the date stamp of NTFS files and so I want to get to this later.

Can someone please direct me to the correct module to use and at least hints in the right direction?

UPDATE. I have updated this test code. The following code works for simple files, at least in the same directory, but it utterly fails for the real subscription folder files, probably because of their length and possibly some restricted characters in the file names with Glob. The code here obviously replaces _ with spaces in the file name, but I hope to include more general modifications via regex at a later date.

Thank you
#!/usr/bin/env perl use strict; use warnings; use autodie; use File::Find; use File::Rename; use Data::Dumper; # VARIABLES # Subscriptions Library & Archive Path variables for clarity my $Subscriptions_Path = "/mnt/hgfs"; # Subscription DATA sets my @Subscription = ( { Sub_Name => "T 1", Lib_Sub_Path => "VM-Share", Keep_Duration => 0, }, { Sub_Name => "T 2", Lib_Sub_Path => "VM-Share/xtr", Keep_Duration => 0, }, { Sub_Name => "T 3", Lib_Sub_Path => "VM-Share/xtr 2", Keep_Duration => 0, } ); for (@Subscription) { print "Beginning Subscription Service for $_->{Sub_Name} \n"; print "The absolute library path is: $Subscriptions_Path/$_->{Lib +_Sub_Path}\n"; my @path = glob("'$Subscriptions_Path/$_->{Lib_Sub_Path}/*'"); print Dumper(\@path); print "\n"; if (@path) { File::Rename::rename(\@path,{ _code => sub { s/_/ / }, verbose => 1, no_action => 1, } ); }; print "Completing Subscription Service for $_->{Sub_Name} \n\n"; }

In reply to How to Rename files in multiple directories with a Perl script using an array of hashes. by ObiPanda

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.