Need help with global file name changes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to change all the filenames in a directory to add text to the
filename.
So if the file name is currently ABC.txt I want to add 03012007 to all the
files so the result would be 03012007ABC.txt and so on, so if the next file
was ABD.txt it woould become 03012007ABD.txt

I remember doing this with a DOS command a long time ago and I think it was
the copy command or the rename command, but I'm not sure. Any Help would be
appriciated.

Thanks
 
Bill Simard said:
I am trying to change all the filenames in a directory to add text to the
filename.
So if the file name is currently ABC.txt I want to add 03012007 to all the
files so the result would be 03012007ABC.txt and so on, so if the next file
was ABD.txt it woould become 03012007ABD.txt

I remember doing this with a DOS command a long time ago and I think it was
the copy command or the rename command, but I'm not sure. Any Help would be
appriciated.

Thanks

You could do this:
1. Click Start / Run / cmd {OK}
2. Type these commands:
cd /d "c:\documents and settings\Bill\My Documents"{Enter}
for /f %a in ('dir *.txt /b') do echo ren "%a" "03012007%a"{Enter}

Omit the word "echo" in the last line to activate the command.

If you intend to do this often then you should consider using
a batch file instead. It would require no typing and it would
insert the correct date code automatically.
 
I understood the CD part to get to the directory I am working with, but you
lost me on the rest of it

for /f %a in ('dir *.txt /b') do echo ren "%a" "03012007%a"{Enter}

Do I type "for /f %a in ('dir *.txt /b') do ren "%a" "03012007%a"

What exactly is that telling windows to do ?

Thanks
 
Bill said:
I am trying to change all the filenames in a directory to add text to the
filename.
So if the file name is currently ABC.txt I want to add 03012007 to all the
files so the result would be 03012007ABC.txt and so on, so if the next file
was ABD.txt it woould become 03012007ABD.txt

I remember doing this with a DOS command a long time ago and I think it was
the copy command or the rename command, but I'm not sure. Any Help would be
appriciated.

Thanks

REN *.txt 03012007*.txt

or

REN *.* 03012007*.*
 
Elmo said:
REN *.txt 03012007*.txt

or

REN *.* 03012007*.*

This was my instinctive thought but on closer inspection
I found that it did not work when I had more than 20
files. Did you ever test it with a large number of files?
 
In my first reply I wrote "2. Type these commands", hence
I wonder why you should ask whether you should type
this command. How else can I express it?

I gave you this command:
for /f %a in ('dir *.txt /b') do echo ren "%a" "03012007%a"{Enter}

When you type it at the Command Prompt then it
will tell you exactly which file it would rename, and how.

The command
for /f %a in ('dir *.txt /b') do ren "%a" "03012007%a"{Enter}
will actually do the rename.

If you are really interested in advanced batch commands
then I can explain what each component of the command
does. If not then I recommend that you run the first version,
convince yourself that it works to your satisfaction, then
run the second version.
 
Bill Simard wrote ::
I am trying to change all the filenames in a directory to add text to the
filename.
So if the file name is currently ABC.txt I want to add 03012007 to all the
files so the result would be 03012007ABC.txt and so on, so if the next file
was ABD.txt it woould become 03012007ABD.txt

I remember doing this with a DOS command a long time ago and I think it was
the copy command or the rename command, but I'm not sure. Any Help would be
appriciated.

Thanks


CD to the folder then run this :

for %x in (*.*) do @ren "%x" "03012007%x"


Good Luck, Ayush.
 
Pegasus said:
This was my instinctive thought but on closer inspection
I found that it did not work when I had more than 20
files. Did you ever test it with a large number of files?

You're probably right then.. I tried it with a small number of files,
just once, the last time I suggested it, and just took it for granted
that it would work with a larger quantity.
 
Pegasus said:
This was my instinctive thought but on closer inspection
I found that it did not work when I had more than 20
files. Did you ever test it with a large number of files?


That seems very odd. I've never tried it myself, and don't have the time
right now, but I'm curious as to whether you have any suggestion as to why
the number of files makes a difference.
 
Joe

You don't need the DOS command

Just select your all your files in the folder then right-click and "rename"

Add the 03012007 prefix and ENTER key.

I just did this with 80 files in a folder..............no problems.

Also went the REN route through Start>Run cmd and entered the path and
REN *.txt 03012007*.txt command.

OK with 80 files.


Gord Dibben MS Excel MVP
 
Try this little experiment from a Command Prompt:

for /L %a in (10,1,50) do @echo. > %a.txt
(to create 50 files)

ren *.txt ABC*.txt
(to add the prefix ABC to all of them)

After the first rename this message appears:
"A duplicate file name exists, or the file
cannot be found."

It seems the command attempts to rename 11.txt to ABC.txt
instead of ABC11.txt.
 
Bill said:
I understood the CD part to get to the directory I am working with,
but you lost me on the rest of it

for /f %a in ('dir *.txt /b') do echo ren "%a" "03012007%a"{Enter}

Do I type "for /f %a in ('dir *.txt /b') do ren "%a" "03012007%a"

What exactly is that telling windows to do ?

Uh, it's renaming all the files in the target directory by precatenating
"03012007" to each file name.

Isn't that what you wanted?
 
Sorry to but in, but I need to do just the opposite. I have 148 files that
start with J and then an underscore such as j_12a or j_12a-b. These are
mapsco pages for out GIS system. The advised they had to put something in
front of the first number. I need to remove the J_ from the 148 file. They
are all name as j_12A.jpg etc. What is the quickest way to do this.
Thank you
 
Ron said:
Sorry to but in, but I need to do just the opposite. I have 148 files that
start with J and then an underscore such as j_12a or j_12a-b. These are
mapsco pages for out GIS system. The advised they had to put something in
front of the first number. I need to remove the J_ from the 148 file. They
are all name as j_12A.jpg etc. What is the quickest way to do this.
Thank you
I have been using the Freeware program THE Rename which can be found at;

http://www.myzips.com/software/THE-Rename.phtml

It is powerful and VERY easy to use.

Ciao . . . C.Joseph

"When hope is lost . . . the spirit dies."
-- Lao Tzu

http://www.tlerma.com/
 
Back
Top