Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need help change my DIR filename from this style: 04_28_2006 (mm_dd_yyyy) to Apr_28_2006.
I am not sure how to change 04 to Apr.Here is whaty I have so far that gets me the 04_28_2006 :
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%mm%_%dd%_%yyyy%
MKDIR "D:\Test\%date%"I am really new at BATCH writing, so any help would be greatly appreciated.
Thank you

First off, you can save yourself all those for statements. Since NT has a built-in DATE var, you can simply use substrings to get the parts you need.
In my case the DATE var is:
Sat 29-04-2006
so doing this:
set YYYYMMDD=%date:~10,4%%date:~7,2%%date:~4,2%
will set a new var called YYYYMMDD
BTW, it's not usually a good idea to alter a built-in var, like DATE.
Moving right along, I guess the simplest way to change 'numeric' month to 'named' month is with a chunk of code like this:
#####
if %MM%==01 set MM=Jan
if %MM%==02 set MM=Feb
if %MM%==03 set MM=Mar
if %MM%==04 set MM=Apr
and so on
#####
=====================================
If at first you don't succeed, you're about average.M2Go

That worked great!
Thank you Mechanix2Go!Plus, thank you for the easier way to get the date in WinXP.

Mechanix2Go..
have you ever run into a situation where the command you entered above doesn't work right..
When I paste your exact line into my cmd window, then check the variable YYYYMMDD's value.. I get:
YYYYMMDD=005/
Ooo.. wait a mo.. brainstorm.. betcha is the date format..
(remote desktop back to 'defective' machine..)
yup..
so the command above is very picky about the format that the Date command returns info in..
thanks for causing the brainstorm! :)
Brett

Hi Brett,
Good work.
The batch below gets the date via BIOS, so the 'layout' is ignored. Unfortunately it needs CMD; won't work in DOS/w3x~Me.
When I first posted it, I said if there was enough interest, I'd work on a DOS silution. So far, there's been, as they say in the Buddhist tradition, a thunderous silence.
::== y6.bat
:: get sys YMD into vars@echo off
:: YYYY getter
> syyyy.d echo a 100
>> syyyy.d echo mov ah,2a
>> syyyy.d echo int 21
>> syyyy.d echo.
>> syyyy.d echo p=100 2
>> syyyy.d echo n sizeYYYY
>> syyyy.d echo w
>> syyyy.d echo q
debug < syyyy.d > nul
:: OK:: MM getter
> sMM.d echo a 100
>> sMM.d echo mov ah,2a
>> sMM.d echo int 21
>> sMM.d echo mov cx,0
>> sMM.d echo mov cl,dh
>> sMM.d echo.
>> sMM.d echo p=100 4
>> sMM.d echo n sizeMM
>> sMM.d echo w
>> sMM.d echo q
debug < sMM.d > nul
:: OK:: DD getter
> sDD.d echo a 100
>> sDD.d echo mov ah,2a
>> sDD.d echo int 21
>> sDD.d echo mov cx,0
>> sDD.d echo mov cl,dl
>> sDD.d echo.
>> sDD.d echo p=100 4
>> sDD.d echo n sizeDD
>> sDD.d echo w
>> sDD.d echo q
debug < sDD.d > nul
:: OK
del *.dfor %%F in (sizeYYYY sizeMM sizeDD) do call :sub1 %%F
set /p YYYY=<sizeYYYY.#
set /p MM=<sizeMM.#
if %MM% LSS 10 set MM=0%MM%
set /p DD=<sizeDD.#
if %DD% LSS 10 set DD=0%DD%
del size*.*
echo YYYYMMDD=%YYYY%%MM%%DD%
goto :eof:sub1
> %1.# echo %~z1
goto :eof
:: DONE
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |