DOS : Batch File Rename

27 Feb

The following batch script will rename the files from the current directory to their creation date and time, with the format YYMMDD-HHMM.extention (the extention will be mantained). The script not only on WinXP, but also in Win95Cmd.EXE, which is somekind of Win2000’s command interpreter emulator.

===== BATCH SCRIPT BEGIN =====
@echo off

if “%OS%”==”Windows_NT” goto OSOK
echo This program must be run in a NT system.
goto eof

:OSOK
if “%1″==”GoTo” goto %2
%comspec% /v /c %0 GoTo start
goto eof

:start
for %%? in (*.*) do (
for /F “tokens=1-6 delims=/-: ” %%A in (“%%~t?”) do (
set MM=%%A
set DD=%%B
set YYYY=%%C
set HH=%%D
set MI=%%E
set AP=%%F
if “!AP!”==”PM” set /A HH += 12
set YY=!YYYY:~-2!
REN %%~s? !YY!!MM!!DD!-!HH!!MI!%%~x?
)
)

:eof
===== BATCH SCRIPT END =====

Another script, which should work on Windows 2000.

===== BATCH SCRIPT BEGIN =====
@echo off
if “%1″==”GoTo” goto %2

ver |FIND “Microsoft Windows 2000” > nul
if not errorlevel=1 goto OSOK
echo This program must be run in Microsoft Windows 2000.
goto eof

:OSOK
%comspec% /v:on /c %0 GoTo start
goto eof

:start
for %%? in (*.*) do (
for /F “tokens=1-6 delims=/-: ” %%A in (“%%~t?”) do (
set MM=%%A
set DD=%%B
set YY=%%C
set HH=%%D
set MI=%%E
if “!MI:~-1!”==”p” set /A HH += 12
set MI=!MI:~0,-1!

:: To activate the script, remove “echo.{demo}” from next line
echo.{demo}REN %%~s? !YY!!MM!!DD!-!HH!!MI!%%~x?

)
)

:eof
===== BATCH SCRIPT END =====

Advertisements

2 Responses to “DOS : Batch File Rename”

  1. Pavel Malikov September 17, 2011 at 2:21 am #

    hey, could you explain ‘%%?’ ?
    what is this variable?
    thanks

  2. Pavel Malikov September 17, 2011 at 2:26 am #

    for?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: