|
|
|
Obligatory perl Reply
ls *.rtf | perl -MFile::Copy -lne '($new = $_) =~ s/\.rtf$/\.ext/i;move($_, $new)'
-MFile::Copy - this tells perl to use the File::Copy module (which provides the move() function) -- this is a built-in module -lne - this is the standard way to call perl on the command line when you pipe output to it and you want it to handle newlines in the expected way. Then you give it the perl code in quotes This next line is kind of weird looking but it's action-packed... it both assigns the value of $_ to the new variable, $new, and then does a search and replace in the next variable's value. It's searching for ".rtf" at the end of the string (case-insensitive, says the "i" after the slash), and replaces it with the new extention (".ext" in this case).
Now we have the old filename ($_, the default variable for the current line of input, and $new, the new and updated filename), so we just call the move() function provided by the File::Copy module. RP |
SearchFrom our Sponsor...Latest Lion HintsWhat's New:HintsNo new hintsComments last 2 days
Links last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2013 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Powered by Geeklog Created this page in 0.11 seconds |
|