473,836 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

rename files in a directory

6 New Member
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 2289
KevinADC
4,059 Recognized Expert Specialist
Is this school work?
Jun 5 '07 #2
mythili123
6 New Member
yes.I am trying my best.Any clue on how to proceed will really help me.
mythili
Jun 5 '07 #3
KevinADC
4,059 Recognized Expert Specialist
look into the rename() function.
Jun 5 '07 #4
miller
1,089 Recognized Expert Top Contributor
perldoc rename

- Miller
Jun 5 '07 #5
mythili123
6 New Member
thank u. .
Jun 5 '07 #6

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

Similar topics

4
17884
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 want to rename it 2004_08_003.jpg. I can understand how to do it to this extent: Ch Dir () ' whatever directory these files are located in Dim stOldName as string, stNewName as string stOldName = 'whatever syntax would go here to 'sense' the...
3
6419
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 = FolderBrowserDialog1.SelectedPath above are the 2 lines of code i have so far, i would like to display/add the files to a list view and i feel that i would have to count the amount of files in the specified directory to do so, so how would i count the amount of files...
5
2737
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 called with an in-use file). However, what happens is that a copy of the file is made, and the old file still exists. For example: C:\>c:\python24\python.exe Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32
3
3637
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 the directories is named 'mydir' (without the quotes). Note that the all the letters in the directory name are in lowercase. To rename any directory/file, one can use the Move method of the Directory/File class respectively but ASP.NET doesn't...
1
2158
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. Attached is the code : # directory structure for input and archive files $inputDir = "\\interac\\Data\\imntran\\".$ARGV; $archDir = "\\interac\\Data\\imntran\\Archive\\".$ARGV; $archSQLLogDir = $archDir."\\SQLlog";
2
3640
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 import listdir, getcwd, rename import re
2
1530
by: shapper | last post by:
Hello, I am using Visual Studio 2008 and Web Deployment Projects: http://blogs.msdn.com/webdevtools/archive/2007/12/01/web-deployment-projects-wdp-for-visual-studio-2008-december-2007-ctp-released.aspx Is it possible to rename a directory and a folder when the web site building finishes? I was trying to do something inside the <Target Name="AfterBuild"but until know I couldn't find a command for this.
1
1622
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 have seemed the obvious choice) so i used python. The files i was renaming were canon raw files (.CR2). my problem is that after i rename the files, OS X will no longer render the thumbnails for the files, and preview is no longer the default...
1
5927
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 which simply moves a zip file (located in the same directory as the source code) to another directory by: <?php $sourcecode = dirname(__FILE__).'\zipfile.zip'; //appending the current directory with the file name $destination =...
0
9654
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10818
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7770
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6972
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4436
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.