Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Multiple File Rename

by perl_n00b (Acolyte)
on Jul 10, 2011 at 20:08 UTC ( #913622=perlquestion: print w/ replies, xml ) Need Help??
perl_n00b has asked for the wisdom of the Perl Monks concerning the following question:

So it's been quite a while since I've done anything in Perl and I was never good to begin with, so I am blanking on how to do this:

All I want is to rename photos with the caption as the file name. I can search for /<rdf:li xml:lang=\"x-default\">(.+?)<\/rdf:li>/ and $1 will be the caption. I could use the rename function to rename a single file 's/$filename/$1/'...if I could remember how to read-in the file name, but I don't, and I also forgot how to read-in a whole directory.

If someone could kindly post the tiny script necessary to do this I would be much obliged. And if you PM me your PayPal email addy I will send you $5 for your trouble, for the first one to do so obviously.

Thanks in advance!

Comment on Multiple File Rename
Re: Multiple File Rename
by i5513 (Monk) on Jul 10, 2011 at 20:42 UTC
    Tell Larry Wall thank you ! You can use his rename program:
    rename 'my $a=$_ ; open XML, "$a.xml"; while (my $l=<XML>) { if ($l =~ /<rdf:li xml:lang=\"x-default\">(.+?)<\/rdf:li>/) { $a=$1} } ; close XML; $_=$a' *
    This code suppose about if you have a file named "xx.png", then there are another file named "xx.png.xml" Regards,
Re: Multiple File Rename
by GrandFather (Sage) on Jul 10, 2011 at 20:50 UTC

    Use perldoc -f xxx to see the docs for function xxx (perldoc -f rename for example). opendir, readdir and closedir are the directory scanning tools.

    Update: s/scandir/readdir/ - thanks kcott.

    True laziness is hard work

      Should that be readdir instead of scandir?

      -- Ken

Re: Multiple File Rename
by Anonymous Monk on Jul 10, 2011 at 20:59 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2015-07-06 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls