1.

Solve : Batch or script to rename directories - Please help?

Answer»

Hi,
I need a script that rename directories from DD.MM.YY format to YY.MM.DD

or aa.bb.cc to cc.bb.aa

Can ANYONE help?

Many thanks



C:\batch>type dirname.bat

Code: [Select]@echo off

SET DD=%1
set MM=%2
set YY=%3
echo %DD%.%MM%.%YY%
md %DD%.%MM%.%YY%

ren %DD%.%MM%.%YY% %YY%.%MM%.%DD%

dir %YY%*
Run:


C:\batch>dirname.bat 19 01 10

Output:

19.01.10
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\batch

01/19/2010 10:12 PM 10.01.19
0 File(s) 0 bytes
1 Dir(s) 303,472,803,840 bytes free

C:\batch>Onimalu:

Are the existing directories you want to rename held in one parent directory or are there other directories within the parent?Thanks for reply directories are like this

1.2.09
12.5.09
6.8.09
2.11.09

and for better sorting I need
09.08.06
09.11.02
etc..

Quote from: Onimalu

directories are like this

1.2.09
12.5.09
6.8.09
2.11.09

What is the PATH to the directories you want to rename?this is not important
I can map it as I want for example D:\1.2.09\

Try this - not fully tested.

Code: [Select]@echo off
setlocal enabledelayedexpansion
cls

:: Syntax: Enter batch script filename followed by the year
:: e.g. script 09
:: script 10

for /F "tokens=1-3 delims=." %%1 in ('dir /ad /b d:\*.%1') do (
set mm=%%1
set dd=%%2
set yy=%%3
set infil=d:\!mm!.!dd!.!yy!
if !mm! lss 10 set mm=0!mm!
if !dd! lss 10 set dd=0!dd!
echo.&echo !infil! will be renamed to !yy!.!mm!.!dd!
rem ren !infil! !yy!.!mm!.!dd!

)

Thank you it works very well.


Discussion

No Comment Found