Nice ☺

From: [email protected] [mailto:[email protected]] On 
Behalf Of Andrew S. Baker
Sent: 04 November 2015 16:11
To: ntsysadm <[email protected]>
Subject: Re: [NTSysADM] Rename Directories

I already have a script that does this 
(http://KB.UltraTech-llc.com/Scripts/?File=BulkRename.BAT) but the way to solve 
your specific problem is not to actually deal with each filename as a single 
token, rather than multiple tokens.

Assuming the folders in question are all in one directory, consider the 
following:

SETLOCAL ENABLEDELAYEDEXPANSION
SET @SOURCE=C:\SomeFolder
FOR /D %%V IN (%@SOURCE%\*) DO (
  SET @OLDNAME=%%~V
  SET @NEWNAME=!@OLDNAME:502010109H=OutProcessedABS!
  SET @RENAME=!@NEWNAME:%@SOURCE%\=!
  IF NOT /I "!@OLDNAME!"=="!@NEWNAME!" (
    ECHO Renaming "!@OLDNAME!" to "!@RENAME!"
    RENAME "!@OLDNAME!" "!@RENAME!"
  )
)


Doing it the way it is above, you won't need to worry about how many segments 
each folder has.  You'll only change the name from X to Y if it has X segment 
in the name.

You can modify the FOR loop if you have the folders more spread out than that 
(perhaps using /R or a lovely /F).

Regards,







ASB
http://XeeMe.com/AndrewBaker<http://xeeme.com/AndrewBaker>
Providing Virtual CIO Services (IT Operations & Information Security) for the 
SMB market…


 GPG: 1AF3 EEC3 7C3C E88E B0EF 4319 8F28 A483 A182 EF3A

On Wed, Nov 4, 2015 at 5:32 AM, Bambi J Saastad 
<[email protected]<mailto:[email protected]>> wrote:
Hoping for some help with renaming directories
I had hoped to just use the move command but I get syntax errors....
The directories are named in this manner
AL1030004_502010109H_20151102_163916
I need to replace the middle 502010109H with OutProcessedABS

so it would become
AL1030004_OutProcessedABS_20151102_163916

I think I need to instead use a for loop, but I cannot get that syntax right 
either
Any quick suggestions?

Thx
B?


-----------------------------
Bambi Saastad
office 952-402-7888<tel:952-402-7888>
cell    612-963-1478<tel:612-963-1478>

Reply via email to