Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I followed your suggestion of dumping the path array and discovered a slight issue with my code. One problem occurred when the directories (and perhaps files) had a space in the naming. I added a single parenthesis on each side and this seemed to fix the problem. The reason I didn't do this before was because I thought single quotes may render my variable a literal. The modification is  my @path = glob("'$Subscriptions_Path/$_->{Lib_Sub_Path}/*'");.

glob might be my friend after all, I just wasn't treating it right. haha. The path array seems to be picking up the files in each of the directories now. So I guess it's the rename that isn't happy with what I'm passing it.

Could rename have an issue with the file length? Here's why I ask.

Going to your second suggestion, I slightly modified the working test code to account for spaces in the directory name. I'll provide the code and then the output, which appears to be perfectly correct here. (Bear in mind, this script is being run from my terminal in the VM but the script and the files and folders are all located on the NTFS file system which is shared with the VM.)

#!/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"; }
Beginning Subscription Service for T 1 The absolute library path is: /mnt/hgfs/VM-Share $VAR1 = [ '/mnt/hgfs/VM-Share/2023-05-23.json', '/mnt/hgfs/VM-Share/Hello my Pony.txt', '/mnt/hgfs/VM-Share/New folder', '/mnt/hgfs/VM-Share/New Text Document.txt', '/mnt/hgfs/VM-Share/pia-linux-3.3.1-06924.run', '/mnt/hgfs/VM-Share/sub_test.pl', '/mnt/hgfs/VM-Share/Subscriptions', '/mnt/hgfs/VM-Share/subscriptions.pl', '/mnt/hgfs/VM-Share/test_rename.pl', '/mnt/hgfs/VM-Share/Torrents', '/mnt/hgfs/VM-Share/UK stopping covid primary vaccinations [ +bpzd74_gZJk].webm', '/mnt/hgfs/VM-Share/xtr', '/mnt/hgfs/VM-Share/xtr 2' ]; rename(/mnt/hgfs/VM-Share/sub_test.pl, /mnt/hgfs/VM-Share/sub test.pl) rename(/mnt/hgfs/VM-Share/test_rename.pl, /mnt/hgfs/VM-Share/test rena +me.pl) rename(/mnt/hgfs/VM-Share/UK stopping covid primary vaccinations [bpzd +74_gZJk].webm, /mnt/hgfs/VM-Share/UK stopping covid primary vaccinati +ons [bpzd74 gZJk].webm) Completing Subscription Service for T 1 Beginning Subscription Service for T 2 The absolute library path is: /mnt/hgfs/VM-Share/xtr $VAR1 = [ '/mnt/hgfs/VM-Share/xtr/test_rename.pl' ]; rename(/mnt/hgfs/VM-Share/xtr/test_rename.pl, /mnt/hgfs/VM-Share/xtr/t +est rename.pl) Completing Subscription Service for T 2 Beginning Subscription Service for T 3 The absolute library path is: /mnt/hgfs/VM-Share/xtr 2 $VAR1 = [ '/mnt/hgfs/VM-Share/xtr 2/Dogs are our_enemies.txt' ]; rename(/mnt/hgfs/VM-Share/xtr 2/Dogs are our_enemies.txt, /mnt/hgfs/VM +-Share/xtr 2/Dogs are our enemies.txt) Completing Subscription Service for T 3

In reply to Re^2: How to Rename files in multiple directories with a Perl script using an array of hashes. by ObiPanda
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-13 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found