Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Rename multiple files following their directories' name

by choroba (Canon)
on Mar 19, 2013 at 11:36 UTC ( #1024274=note: print w/ replies, xml ) Need Help??


in reply to Rename multiple files following their directories' name

You can probably use a shell for this task:

for folder in folder* ; do [ -f $folder/abc.txt ] && mv $folder/abc.txt $folder/$folder.txt done

In Perl, the solution is quite similar:

for my $folder (glob 'folder*') { # or (grep -d, glob 'folder*') rename "$folder/abc.txt", "$folder/$folder.txt" if -f "$folder/abc +.txt"; }

(Untested)

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Rename multiple files following their directories' name
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-07-06 03:02 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 (69 votes), past polls