473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

rename files in a directory

The script will rename
all files in the current directory whose names contain the first argument
by replacing that part of the filename with the second argument.

so far i could just get the file names that matches $ARGV[0].I need help on how to rename the files .For ex if argumnets are a bbb
if a file name is rename.txt
then O/P must be renbbbme.txt.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. use File::Find;
  5. die"Usage:$0 filename newname\n" if @ARGV!=2;
  6. my ($filename, $newname) = @ARGV;
  7.  
  8. opendir(D,".") or die "Cannot open .: $!";
  9.  
  10. my @allfiles = ();
  11. foreach my $file (readdir D) {
  12.     next if -d "$file";
  13.     next if $file !~ m/[\Q$ARGV[0]\E]/;
  14.     push @allfiles, $file;
  15. }
  16. print "@allfiles\n";
  17.  
Thanks
Mythili
Jun 5 '07 #1
5 2267
KevinADC
4,059 Expert 2GB
Is this school work?
Jun 5 '07 #2
yes.I am trying my best.Any clue on how to proceed will really help me.
mythili
Jun 5 '07 #3
KevinADC
4,059 Expert 2GB
look into the rename() function.
Jun 5 '07 #4
miller
1,089 Expert 1GB
perldoc rename

- Miller
Jun 5 '07 #5
thank u. .
Jun 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Larry R Harrison Jr | last post by:
I have Access XP. I know Visual Basic quite well. One thing I know Access can do--and I can't quite figure out how--is to rename the files in a directory. If the file is named "aug01_003.jpg" I...
3
by: glub glub | last post by:
i'm trying to make a program that works as Replace works in MS Word but this is for use with files, not a text document. FolderBrowserDialog1.ShowDialog() txtPath.Text =...
5
by: Tony Meyer | last post by:
On Windows, if I do os.rename(old, new) where old is a file that is in-use (e.g. python itself, or a dll that is loaded), I would expect that an error would be raised (e.g. as when os.remove is...
3
by: rn5a | last post by:
An inquisitive question...... A ListBox lists all the directories & files residing in a directory on the server. Assume that the ListBox lists 2 directories & 4 files. Also assume that one of...
1
by: codemaster | last post by:
Hi, I am a total novice to perl. I am moving files from one directory to another and trying to rename a file appending the timestamp. But for some reason, my code is not able to rename. ...
2
by: =?iso-8859-1?b?cultaQ==?= | last post by:
Hi, I would like to rename files (jpg's ones) using a text file containing the new names... Below is the code that doesn't work : ***** #!/usr/bin/python #-*- coding: utf-8 -*- from os...
2
by: shapper | last post by:
Hello, I am using Visual Studio 2008 and Web Deployment Projects:...
1
by: lukas | last post by:
hello, i recently had the job of having to rename about 200 files. The source for the renaming was a bunch of names in a file. I know next to nothing when it comes to bash scripting (which would...
1
by: Alien | last post by:
Hi, I am new to PHP and trying to move a zip file from one directory to another. I researched on the web on this and all fingers pointed to this rename() function. I tried writing a PHP script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.