Solved batch file to create folder with y'day date??

June 9, 2011 at 10:21:16
Specs: Windows XP
hi guys,

i want to create a folder with naming as yesterday date.can anyone help me out.i require dis to do my office work as daily task.plz help me


See More: batch file to create folder with yday date??

Report •


#1
June 9, 2011 at 15:44:08
✔ Best Answer
It could be normal to format the date in yyyymmdd format for naming folders/files but you don't specify what format is required or what your current system date format is. The following will hopefully create a folder in your current system date format, it is assumed that your date separator is currently forward slash (/).

@echo off
setlocal enabledelayedexpansion
cls

set vbs=%temp%\vbs.vbs

> %vbs% echo WScript.Echo DateAdd("d",-1,Date)

for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do (
    set newfold=%%a&set newfold=!newfold:/=-!
    md "!newfold!"
    echo New folder created !newfold!
)


Please come back & tell us if your problem is resolved.


Report •

#2
June 12, 2011 at 22:05:27
thanks a lot for your reply...

can i have the format DD-MM-YYYY?


Report •

#3
June 13, 2011 at 01:32:04
What is your current date format??? Enter date /t or echo %date%
at the command prompt and post results please.


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
June 13, 2011 at 01:50:30
hi,
please find the output below.

C:\Documents and Settings\switch.engineer>date/t
Mon 06/13/2011

C:\Documents and Settings\switch.engineer>


Report •

#5
June 13, 2011 at 12:25:09
This should do what you want - it is untested and is good for only the system date format you posted:

@echo off
setlocal enabledelayedexpansion
cls

set vbs=%temp%\vbs.vbs

> %vbs% echo WScript.Echo DateAdd("d",-1,Date)

for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do (
    set newfold=%%a
    )
del %vbs%

for /f "tokens=1-3* delims=/ " %%1 in ("%newfold%") do (
    set month=%%2&set date=%%3&set year=%%4
    md !date!-!month!-!year!
    echo New folder created = !date!-!month!-!year!
 )


Please come back & tell us if your problem is resolved.


Report •

#6
June 14, 2011 at 23:26:19
HI,
NEW FOLDER CREATING,BUT FORMAT IS AS YYYY-DD-

not getting the month.


Report •

#7
June 15, 2011 at 00:44:13
Please copy/paste the script you are using.


Please come back & tell us if your problem is resolved.


Report •

#8
June 15, 2011 at 00:48:00
@echo off
setlocal enabledelayedexpansion
cls

set vbs=%temp%\vbs.vbs

> %vbs% echo WScript.Echo DateAdd("d",-1,Date)

for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do (
set newfold=%%a
)
del %vbs%

for /f "tokens=1-3* delims=/ " %%1 in ("%newfold%") do (
set month=%%2&set date=%%3&set year=%%4
md !date!-!month!-!year!
echo New folder created = !date!-!month!-!year!
)
PAUSE


Report •

#9
June 15, 2011 at 12:26:33
SATISH - Sorry, I cannot find any fault with the script you posted, it works perfectly here. When you run it twice do you get the error message that A subdirectory or file ........ already exists?


Please come back & tell us if your problem is resolved.


Report •

#10
June 17, 2011 at 02:41:41
"New folder created = 2011-16-"
I'M getting the above msg only

Report •

Ask Question