File Renaming

I have a folder with sub-folders all named with _XX in the last three characters. I would like to have a batch program that removes these last three charaters.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


This program is a batch folder renaming suite that will allow you to remove characters in a batch process.
Check out this link - it has several freeware solutions you can pick from.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Save the following as, say, RemXX.vbs.  Place the vbs file in the parent folder and run it. It will ask if you want to add _XX or remove it.

It only acts on the immediate subfolder level.  You could alter it to be recursive if you want it to act on all sub-subfolders.
call main()
sub main()
dim startFolder, thisFolder, subFolders, cFolder, fso, fName
dim askResult
askResult = msgbox("Add _XX suffix?" & vbNewLine & vbNewLine & "Click 'Yes' to add suffix." & vbNewLine & "Click 'No' to remove existing _XX suffix.",3)
'msgbox "return: " & cstr(askResult)
if askResult = 2 then
	exit sub
elseif askResult = 6 then
	doAdd = true
	doAdd = false
end if
set fso = CreateObject("scripting.filesystemobject")
set startFolder = fso.GetFolder(".")
set subFolders = startFolder.SubFolders
for each thisFolder in subFolders
	fName =
	'msgbox fName
	if doAdd then
		fName = fName & "_XX" = fName
		if right(fName, 3) = "_XX" then
			fName = left(fName, len(fName)-3) = fName
		end if
	end if
end sub

Open in new window

This will only rename folders with has the 3rd last character as "_".

Change the set folder= to your base folder.
Set Folder=C:\Files
for /f %%a in ('dir /ad /b "%Folder%"') do (
    Set Subfolder=%%a
    IF "!SubFolder:~-3,1!" == "_" REN "%Folder%\%%a" "!SubFolder:~0,-3!"

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.