Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

renaming files from a tab delimited list

by flieckster (Scribe)
on Mar 16, 2016 at 15:22 UTC ( [id://1157947]=perlquestion: print w/replies, xml ) Need Help??

flieckster has asked for the wisdom of the Perl Monks concerning the following question:

hey all, just wondering if anyone has ever tackled renaming files in folder using a tab delimited list, or other list. for example:

file.psd > otherfilename.psd

or

p1234_alt1.psd > p4321_alt1.psd

can anyone point me in the right direction?

  • Comment on renaming files from a tab delimited list

Replies are listed 'Best First'.
Re: renaming files from a tab delimited list
by 1nickt (Canon) on Mar 16, 2016 at 15:30 UTC

    Hi flieckster,

    Please show the code you've tried, and why it doesn't work. Post your code inside <code> tags, and include a sample of the data you're processing and the expected output.


    The way forward always starts with a minimal test.
      i have no code to show at this point since I wasn't sure where to start. if you could point me to a module that might work i can start from there.

        For file operations: Path::Tiny

        use strict; use warnings; use feature 'say'; use Path::Tiny qw/ path /; say qx# ls /tmp/*.txt #; my $dir = '/tmp/'; my $ext = '.txt'; my $regex = qr/$ext/; my @paths = path( $dir )->children( $regex ); for my $file ( @paths ) { my $name = path( $file )->basename( $regex ); my $newname = join '', reverse split '', $name; path( $file )->move( join '', $dir, $newname, $ext ); } say qx# ls /tmp/*.txt #; __END__
        Output:
        /tmp/bar.txt /tmp/foo.txt /tmp/oof.txt /tmp/rab.txt

        Hope this helps!


        The way forward always starts with a minimal test.

        perlintro will give you all the information and example code you need to open and read the file containing your tab delimited list. Inside the loop that reads that file line by line, you could use split to split each line into its components, and then rename to rename the files. Try writing some code, posting it here (following the guidelines in How do I post a question effectively?), and I'm sure someone will be happy to help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1157947]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found