Rename with wildcards?

B

Bill H

Can the following be done in Perl using the rename command (I looked in
the perldoc and it doesn't state if you can or can't use wildcards).

rename "OLD*.*","NEW*.*";

And any file starting with "OLD" is renamed to start with "NEW".

Thanks in advance - and if you want to point me to the right place to
look please do.

Bill H www.ts1000.us
 
B

Brian McCauley

Bill said:
Can the following be done in Perl using the rename command (I looked in
the perldoc and it doesn't state if you can or can't use wildcards).

No you cannot use wildcards. Wildcards are not a low-level filesystem
feature. Perl's rename() is just an interface to the low leve OS
rename.

In Perl shell-like wild cards are implemented using the glob() function
(and a loop).
rename "OLD*.*","NEW*.*";

And any file starting with "OLD" is renamed to start with "NEW".

for my $old ( glob 'OLD*.*' ) {
(my $new = $old) =~ s/^OLD/NEW/ or die;
rename $old, $new or warn "$old -> $new: $!";
}
 
P

Paul Lalli

Bill said:
Can the following be done in Perl using the rename command (I looked in
the perldoc and it doesn't state if you can or can't use wildcards).

rename "OLD*.*","NEW*.*";

I really hate the question "can this be done?". The obvious answer is
"Try it and see."
And any file starting with "OLD" is renamed to start with "NEW".

Thanks in advance - and if you want to point me to the right place to
look please do.

Look into the following perldocs:
perldoc -f glob
perldoc perlretut

Paul Lalli
 
B

Bill H

Paul said:
I really hate the question "can this be done?". The obvious answer is
"Try it and see."

I don't think it is a good idea to "try it and see" when the perl
routine is running on a webserver with 30 more other websites. If I try
it locally on a dos box and it does or doesn't work that doesn't tell
me what it will do on the server running Linux, hence the question.

On the other response about using glob, that is basically what I am
doing already, was just hping there was a better way of doing it.
 
D

DJ Stunks

Bill said:
I don't think it is a good idea to "try it and see" when the perl
routine is running on a webserver with 30 more other websites. If I try
it locally on a dos box and it does or doesn't work that doesn't tell
me what it will do on the server running Linux, hence the question.

Try thinking outside the box, there Billy:

[server ~]$mkdir tmp
[server tmp]$cd tmp
[server tmp]$touch OLD.file
[server tmp]$perl -e 'use strict;use warnings;rename
"OLD*.*","NEW*.*";'
[server tmp]$ls *.file
OLD.file

-jp
 
P

Paul Lalli

Bill said:
I don't think it is a good idea to "try it and see" when the perl
routine is running on a webserver with 30 more other websites.

Are you telling me you don't have any test environments to try out
code?
If I try
it locally on a dos box and it does or doesn't work that doesn't tell
me what it will do on the server running Linux, hence the question.

What company is this that expects their developers to try out all
programs on the live servers without any testing? I'd like to know for
my own piece of mind to make sure I don't have anything to do with
them.
On the other response about using glob, that is basically what I am
doing already, was just hping there was a better way of doing it.

Then you should have stated that in your original post, instead of
having us waste our time by giving you the same answer you already had.

Paul Lalli
 
A

Aaron Baugher

Bill H said:
Can the following be done in Perl using the rename command (I looked
in the perldoc and it doesn't state if you can or can't use
wildcards).
rename "OLD*.*","NEW*.*";

Why not try it and see what happens? It doesn't work on my FreeBSD
system, but see what it does on your DOS-based system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FAQ 5.20 How can I reliably rename a file? 0
Help with rename function 2
Negative Lookbehind and Wildcards 3
using wildcards with -e 46
Rename Perl Process 8
Rename of FileName using PERL 2
wildcards 25
rename 7

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top