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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |