473,624 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global renaming of files

Hi folks

I have some 1600 files where the first 7 characters of each file name is in
the format "CN NNN ". I would like to be able to change these via a program
to the format "CN-NNN-". The files are actually hymns and these 7 characters
are followed by the first line of the hymn.

Can anyone out there help, or do I have to go through manually making the
changes? I would appreciate any valid comments.

Thanks everybody

Aug 11 '06 #1
1 1165
Jaymac <Ja****@discuss ions.microsoft. comwrote:
I have some 1600 files where the first 7 characters of each file name is in
the format "CN NNN ". I would like to be able to change these via a program
to the format "CN-NNN-". The files are actually hymns and these 7 characters
are followed by the first line of the hymn.

Can anyone out there help, or do I have to go through manually making the
changes? I would appreciate any valid comments.
I use a sed & mv script I call 'rename' for things like this, but it
works on Cygwin or other Unix-like systems. With it, I'd do this:

rename 's:\(..\) \(...\) :\1-\2-:' C*

.... but this may be impractical for you.

---8<--
#!/bin/bash
#
# Written by Barry Kelly, 19 January 2004
#

function syntax {
echo "Syntax:"
echo " $(basename $0) <sed-script<file>+"
echo "Files are renamed to new names tranformed by the sed script."
echo "For example, the command:"
echo " $(basename $0) s/foo/bar/g"
echo "renames all files which contain 'foo' to contain 'bar'
instead."
}

if [ $# -lt 2 ]; then
syntax
exit 1
fi

case "$1" in -h | -H | --help)
syntax
exit
esac

sed_script="$1"
shift

function process {
local old_name="$1"
local new_name="$(ech o "$1" | sed "$sed_scrip t")"
if [ "$old_name" = "$new_name" ]; then
echo "Skipping $new_name, still the same."
return
fi
if test -f "$new_name" ; then
mv -i -- "$old_name" "$new_name. tmp"
mv -i -- "$new_name. tmp" "$new_name"
else
mv -i -- "$old_name" "$new_name"
fi
}

while [ "$1" ];
do
process "$1"
shift
done
--->8---

-- Barry

--
http://barrkel.blogspot.com/
Aug 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
10667
by: qaz | last post by:
For some reason my global.asa file is not firing. I have it located in the root of my website (e.g., wwwroot\mywebsite\global.asa) and I have the web site configured as an "application" in IIS. When I modified the file I also stopped and restarted the web server. Can anyone give me some ideas as to why it is not firing? Thanks
0
1965
by: MikeY | last post by:
Hopefully someone can help, I have a listview box where I display my desired files. I single click on the desired file to be renamed and I rename it with a new name. My problem arises when the new name gets displayed through refreshing of my loop and display function. The problem is that when, if I rename the last file entry, everything appears to display fine. If I rename a file above the last entry (bottom entry), two of the new file...
1
3423
by: Don Leverton | last post by:
Hi Folks, I have been given a CD with approx 130 .xls files (bean-counters!) that I would like to import and merge to ONE table (tblTradeshow). The XL files are *similarly*, but not identically structured, and the first row does NOT contain field names. Some (actually most) of the column names *are* the same in all of the spreadsheets.
1
1632
by: ravinder thakur | last post by:
hi all experts, i am porting a project from c to the c++ framework. during the porting i have encounterd a where i have a static and a global variable with the same name. now what rules c languages uses to reslolve the ambiguity between these two variables with the same names. more specifically what will happen if the both of these varaibles gets included in some compilation unit due to the interdependency between the header files???
44
3608
by: fabio | last post by:
Why? i' ve heard about this, the usage of global vars instead of locals is discouraged, but why? thx :)
9
356
by: Shilpa | last post by:
Hi, I just wanted to know whether we can access global variable within a local block , where both variables are having same name. For ex: int temp=5 ; { int temp=10;
1
7197
by: GeoDW | last post by:
Hell All, I have looked around and not found the solution I am looking for within the old threads. Here is my problem: I have a directory full of .img and .rrd files that have long filenames that need to be trimmed down because the program I am using to open these files lists them not only by the name, but by how many characters are in the name. Here is an example of a filename and how I want it to look afterward: ...
18
5729
by: =?Utf-8?B?dmJ0cnlpbmc=?= | last post by:
Is it possible to create a 'global variable' in C# that can be used and accessed between forms? I've used MODULES in Visual Basic, but can't find the equivalent for C# ... Thanks to all those responding,
2
3585
by: Alan Mailer | last post by:
I am relatively new to VB.net. I want to change the name of a Project and change the name of the files in the Project's various folders to reflect that new project name. Is there something I can do within the Project itself to make this happen? Every time I've attempted to do this by hand (including going through the Project's folders and renaming files from say "MyOldProjectName.exe" to "MyNewProjectName.exe"), something gets
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8688
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
8494
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...
0
7178
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
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
5570
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
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.