Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Batch rename in DOS or Windows Powershell

29 Jan 2013   #1

Windows7 64
Batch rename in DOS or Windows Powershell

Hi - sorry if this is not the right forum - please feel free to move this is need be.

So, I have this for batch renaming files in a folder:

Dir | rename-item -newname { $ -replace "oldname","newname" }

And it works like a charm. The thing I can not figure out how to do is add characters - w/o changing any. So let's say I have 3 files: 1.txt 2.txt and 3.txt - I want to change them to be x1.txt x2.txt and x3.txt

So I try replacing 'replace' with 'add' like this:

Dir | rename-item -newname { $ -add "x", }

But it doesn't work. Does anyone know if this is possible, and if so, what I am missing in my command line?


My System SpecsSystem Spec
29 Jan 2013   #2

Windows 8 Pro (32-bit)

DOS - String Manipulation (String Concatenation)

If I had to guess, the code you need is:
Dir | rename-item -newname { %$ }
I modified a vbs script I wrote for someone else. This will work while respecting extensions, but it'll also rename folders
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\path\to\folder\of\files"
Set objFolder = objFS.GetFolder(strFolder)
For Each File In objFolder.Files
	strFileName = File.Name
	For i=1 To Len(strFileName)
		if Mid(strFileName,i,1) = "." Then
			strEndOfFirst = i
		End If
	strFirstName = Mid(strFileName,1,strEndOfFirst - 1)	
	strLastName = Mid(strFileName,strEndOfFirst)
	strNewName = strFirstName & "x" & strLastName
save a rename.vbs , and change "C:\path\of\folder\of\folders" to the folder where the files are located

After that, I'd recommend taking a look at ReNamer. it's pretty powerful and should do what you want easily.
My System SpecsSystem Spec

 Batch rename in DOS or Windows Powershell

Thread Tools

Similar help and support threads
Thread Forum
mass/batch file rename rollback?
Hey all, Last night i renamed a bunch of files. Is there a way to undo all of that? the changes i made last night were pretty much 36327780_p0_master1200 >>> 36327780_p0 system restore doesn't restore files and documents, so that one's a dead end...
General Discussion
'Rename' box doesn't show up when I rename a file shortcut
So basically (I'll try to be descriptive), I have an Excel file (extension xlsm) on my USB and I right click it, send to --> desktop (create shortcut). I see the shortcut. I right click and attempt to rename it with a different file extension, but the 'Rename' box doesn't show up like I believe it...
General Discussion
Batch file or Exe to copy & rename directory and update files
I require a batch file or free utility that i can redistribute from my web site to other users, (gamers) that will copy the contents of a directory inside their game to a new location and re-name the directory at the same time. Something like this; Copy "Genesis\Vehicles\truck\diesel\4tonbaker"...
General Discussion
Portin from Batch to Powershell?
Hallo, Im starting to work with powershell and try to port my old batch files. Im encounter some problem you may help me with. 1) I got this lines of Code, and I dont know who to convert them to power shell. The goal is to uninstall a software using the string found in the registry. ...
General Discussion
Delate, rename through batch files?
Hi all, So I'm trying to make a personal shortcut on my computer to change a password using the shiftkeys .exe (C:\Windows\System32\sethc.exe) which can be done from setup. I'm looking to design this because I frequently deal with friends and family who have forgotten passwords, as well as my...
General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 17:52.
Twitter Facebook