Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

File Renaming

Posted on 2008-11-07
4
Medium Priority
?
196 Views
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.
0
Comment
Question by:scsoil
4 Comments
 
LVL 6

Expert Comment

by:GCD1
ID: 22908290
http://www.skyjuicesoftware.com/software/ffr_info.html

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

Accepted Solution

by:
97WideGlide earned 500 total points
ID: 22908347
Check out this link - it has several freeware solutions you can pick from.

http://www.snapfiles.com/Freeware/system/fwfilerename.html
0
 
LVL 1

Expert Comment

by:PotentisFrog
ID: 22908488
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
else
	doAdd = false
end if
set fso = CreateObject("scripting.filesystemobject")
set startFolder = fso.GetFolder(".")
'msgbox startFolder.name
set subFolders = startFolder.SubFolders
for each thisFolder in subFolders
	fName = thisFolder.name
	'msgbox fName
	if doAdd then
		fName = fName & "_XX"
		thisFolder.name = fName
	else
		if right(fName, 3) = "_XX" then
			fName = left(fName, len(fName)-3)
			thisFolder.name = fName
		end if
	end if
next
end sub

Open in new window

0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22913377
This will only rename folders with has the 3rd last character as "_".

Change the set folder= to your base folder.
SETLOCAL ENABLEDELAYEDEXPANSION
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

0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

578 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