| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| General Discussion / Chit Chat Free form discussion forum to discuss issues that do not belong in any of the other boards. NOTE: Posts in this forum do not count towards totals. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Renaming multiple files in DOS
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. |
|
#2
|
|||
|
|||
|
Re: Renaming multiple files in DOS
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 |
|
#3
|
||||
|
||||
|
Re: Renaming multiple files in DOS
Pretty sure you can use a SINGLE-CHARACTER WILDCARD. Not sure if it's & or _
Code:
ren t&&&*.txt track*.txt
__________________
David CodeGuru Article: Bound Controls are Evil-VB6 101 Samples: VB & C# VS2008 Samples & VS2010 Samples CodeGuru Reviewer 2006 Dell CSP 2006, 2007 & 2008 MVP Visual Basic If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!
|
|
#4
|
|||
|
|||
|
Re: Renaming multiple files in DOS
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 |
|
#5
|
|||
|
|||
|
Re: Renaming multiple files in DOS
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.
|
|
#6
|
|||
|
|||
|
Re: Renaming multiple files in DOS
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. |
|
#7
|
||||
|
||||
|
Re: Renaming multiple files in DOS
Once again, try VBSCRIPT
Code:
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
__________________
David CodeGuru Article: Bound Controls are Evil-VB6 101 Samples: VB & C# VS2008 Samples & VS2010 Samples CodeGuru Reviewer 2006 Dell CSP 2006, 2007 & 2008 MVP Visual Basic If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!
|
|
#8
|
|||
|
|||
|
Re: Renaming multiple files in DOS
Hi dglienna,
Thanks for the post. |
|
#9
|
|||
|
|||
|
Re: Renaming multiple files in DOS
If you install Cygwin, the following will work in the Cygwin prompt:
Code:
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 |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|