Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 175 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a folder with name as current date in batch (.bat) files

#1
I don't know much about windows .bat file syntax. My simple requirement is to create a folder at a specific location with name as current date. I tried searching this on google but didn't get any good option. Is there any way to do this?
Reply

#2
This should work:

mkdir %date%

If it doesn't, try this:

setlocal enableextensions
mkdir %date%
Reply

#3
Try this (an equivalent of bash backquotes):

for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
mkdir %datestr%


For further information, see [

[To see links please register here]

][1]


[1]:

[To see links please register here]

Reply

#4
You need to get rid of the '/' characters in the date before you can use it in mkdir like this:

setlocal enableextensions
set name=%DATE:/=_%
mkdir %name%

Reply

#5
mkdir %date:~-4,4%%date:~-10,2%%date:~7,2%
Reply

#6
echo var D = new Date() > tmp.js
echo D = (D.getFullYear()*100+D.getMonth()+1)*100+D.getDate() >> tmp.js
echo WScript.Echo( 'set YYYYMMDD='+D ) >> tmp.js
echo @echo off > tmp.bat
cscript //nologo tmp.js >> tmp.bat
call tmp.bat
mkdir %YYYYMMDD%
Reply

#7
Quick and dirty: If you can live with the date being UTC instead of local, you can use:

for /f "skip=1" %%d in ('wmic os get localdatetime') do if not defined mydate set mydate=%%d
md %mydate:~0,8%

Works in all locales. Only on XP and higher, though.
Reply

#8
I had a problem with this because my server ABSOLUTELY had to have its date in MM/dd/yyyy format, while I wanted the directory to be in YYYY-MM-DD format for neatness sake. Here's how to get it in YYYY-MM-DD format, no matter what your regional settings are set as.

Find out what gets displayed when you use %DATE%:

From a command prompt type:

ECHO %DATE%

Mine came out 03/06/2013 (as in 6th March 2013)

Therefore, to get a directory name as 2013-03-06, code this into your batch file:

SET dirname="%date:~6,4%-%date:~0,2%-%date:~3,2%"
mkdir %dirname%
Reply

#9
this is a more simpler solution.

@ECHO OFF
set name=%date%
echo %name%
mkdir %name%
Reply

#10
for /F “tokens=1-4 delims=/ ” %%A in (‘date /t’) do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C
)
set CurrentDate=%DateDay%-%DateMonth%-%DateYear%
md %CurrentDate%

This will give you a newly created folder with today’s date, in the format of DD-MM-YY

Sourced from: [Ali's Knowledge Base][1]


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through