Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: file compare and renaming

by brx (Pilgrim)
on Apr 20, 2012 at 06:53 UTC ( [id://966106]=note: print w/replies, xml ) Need Help??


in reply to file compare and renaming

Take a look to rename and perlrun (-n -l -e) (update: and perlretut).
An adhoc one-liner can do the job.
Try this...
ls | perl -nle '$a=$_;s/.*?(S\d\dE\d\d).*?\.(avi|srt)/LikeABoss${1}Yea +h.$2/;print "$a => $_"'
... then if everything seems OK (no files with the same "SxxEyy" for example)
ls | perl -nle '$a=$_;s/.*?(S\d\dE\d\d).*?\.(avi|srt)/LikeABoss${1}Yea +h.$2/;rename $a,$_'
But don't feel to confident with this : it is a good idea to write a real script if you want to automate this task without human-control. Not my fault if you lose all your pictures/movies/files.

Update:
Add this check.
Count file before renaming:
ls | wc -l

Number of file that should results:
ls | perl -nle '$a=$_;s/.*?(S\d\dE\d\d).*?\.(avi|srt)/LikeABoss${1}Yea +h.$2/;$h{$_}++}{print scalar keys%h'

This way you can't lose the files, only the filenames ;-)

Replies are listed 'Best First'.
Re^2: file compare and renaming
by Anonymous Monk on Apr 20, 2012 at 07:07 UTC

    But don't feel to confident with this : it is a good idea to write a real script ...

    :)I'd say that is good advice , write a real script that doesn't rename files :)

    Over the years i've written dozens of renaming scripts, and not doing any actual renaming is the best advice I've got :) Generate a list of moves, review the moves (check collisions, orphans ...), and keep backups

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found