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

Re:{3} File renaming and removal to a subdirectory

by jeroenes (Priest)
on Jul 11, 2001 at 17:22 UTC ( #95671=note: print w/ replies, xml ) Need Help??


in reply to File renaming and removal to a subdirectory
in thread File renaming and removal to a subdirectory

When I started with perl, I greatly enjoyed 'Learning Perl' from Randall L. Schwartz aka merlyn. Great book for the first steps in perl.

There are two things that you need to do here. First, create a list of files you want to move around. That's done by globbing: @list = <*.puz>.

Than you'll have to rename that file to add the 'A' and move it at the same time, the first part is done by regexes, see perlre: s/(\.puz)$/A$1/; and the second by concatenation: $name= 'subdir/' . $name.

You'll have to rename every file, so loop over your list with for:

for my $new ( <*.puz> ){ my $old = $new; $new =~ s/(\.puz)$/A$1/; $new = 'subdir/' . $new; rename $old, $new; }

Updated


Comment on Re:{3} File renaming and removal to a subdirectory
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-07-28 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls