Click to See Complete Forum and Search --> : Renaming multiple files in DOS


Tienshan
February 10th, 2010, 01:34 AM
Hi All,
I am in a situation like this:
I have close to 100 files ordered like this:
test1.txt
test2.txt
test3.txt
...
...
test99.txt

I need to rename those files like this:
track1.txt
track2.txt
...
...
track99.txt
i.e. trackNN.txt

Of course, with windows, I can rename them whatever I like one by one.

But with commad prompt (DOS command) how do I do that?

ren test*.txt track*.txt did not work
I want to change the alphabet part, leaving the numerals intact.

Is it possible?

Thank you for your time.

Best,
T.

olivthill2
February 10th, 2010, 08:34 AM
There is no easy way to do this in a ".bat" file.
Instead you could do this in VBS (VBS is the scripting language supposed to replace old DOS commands, and is available since Windows 95).
Or, better, use a good third party tool, e.g. ant renamer. See http://www.antp.be/software/renamer

dglienna
February 10th, 2010, 06:22 PM
Pretty sure you can use a SINGLE-CHARACTER WILDCARD. Not sure if it's & or _

ren t&&&*.txt track*.txt

Otherwise, look into POWERSHELL. It can do that

Tienshan
February 11th, 2010, 08:17 PM
Hi olivthill2, dglienna,
Thank you for your answers.

ren t&&&*.txt track*.txt and ren t___*.txt track*.txt did not work.

I will have to use some other ways. Let's see if I can use powershell- never used this before.
T

thisismyusername2010
February 11th, 2010, 08:43 PM
I don't know if this works on all windows computers, but on windows vista if you select all the files you want to rename, then press F2, it'll allow you to rename a file and then it will take that same name and name all the files selected under that name and number them. Pretty easy and convenient alternative.

Tienshan
February 11th, 2010, 11:54 PM
Hi,
Yes, even in my XP, it works. I mean it renames files like track (1).txt, track (2).txt, etc.
Unfortunately, for my purpose, that was not useful.
The end device that uses the files (track1.txt, track2.txt.....) could not read track (1).txt, track (2).txt, etc.
Thanks.

dglienna
February 12th, 2010, 07:00 PM
Once again, try VBSCRIPT

Const ForReading = 1

strComputer = "."
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\scripts\names.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
arrParts = Split(strLine, ",")
strFile = "C:\\Pictures\\" & arrParts(0)
Set colItems = objWMIService.ExecQuery _
("Select * From CIM_Datafile Where Name = '" & strFile & "'")
For Each objItem in colItems
strNewName = "C:\Pictures\" & arrParts(1)
objItem.Rename strNewName
Next
Loop

objFile.Close


http://blogs.technet.com/heyscriptingguy/archive/2006/05/11/how-can-i-rename-files-using-file-names-i-ve-written-to-a-text-file.aspx

Tienshan
February 14th, 2010, 11:44 AM
Hi dglienna,
Thanks for the post.

maxtothemax
February 14th, 2010, 02:46 PM
If you install Cygwin, the following will work in the Cygwin prompt:
cd "/cygdrive/c/Documents and Settings/whatever folder/the files are in/"
for i in `ls` ; do mv $i `echo $i | sed "test/track/"`; done