File Renaming

Posted on 2008-11-07
Last Modified: 2012-05-05
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.
Question by:scsoil
    LVL 6

    Expert Comment


    This program is a batch folder renaming suite that will allow you to remove characters in a batch process.
    LVL 8

    Accepted Solution

    Check out this link - it has several freeware solutions you can pick from.
    LVL 1

    Expert Comment

    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

    LVL 21

    Expert Comment

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now