Solved

how to create directory dynamically in a batch file with current date and time as the name

Posted on 2004-09-08
5
142 Views
Last Modified: 2010-04-14
Hi All,

I have a requirement where I am copying some log files to a directory when the services stops and re-starts. I have a batch file to do that. But I want to have a command for creating a directory dynamically (md <somevariable>) and I want the directory name to be the date and time at that moment.

How can I do this?

I will appreciate any inputs on this.

thanks..

regards
rafi
0
Comment
Question by:syberian
5 Comments
 
LVL 23

Expert Comment

by:rhandels
ID: 12011683
Hi,

i thought this was the now() command (or something like that). You could test it within an Access database or something lik that to see if ot works. You will need to create a .vbs file to do this. There isn't a dos command to do this..
0
 
LVL 83

Expert Comment

by:oBdA
ID: 12013699
Try something like that:

for /f "tokens=1-3 delims=/ " %%a in ('date /t') do set MyDate=%%c-%%a-%%b
for /f "tokens=1* delims=:" %%a in ('time /t') do set MyTime=%%a%%b
ECHO md %MyDate%_%MyTime%
0
 
LVL 16

Accepted Solution

by:
Richard Olutola earned 50 total points
ID: 12925278
@echo off
call :GetDate year month day
:: echo/Today is: %year%-%month%-%day%
md %year%-%month%-%day%
goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetDate yy mm dd
::
:: By:   Ritchie Lawrence, 2002-06-15. Version 1.0
::
:: Func: Loads local system date components into args 1 to 3. For NT4/2K/XP
::
:: Args: %1 var to receive year, 4 digits (by ref)
::       %2 var to receive month, 2 digits, 01 to 12 (by ref)
::       %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
  for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
    set %%a=%%d&set %%b=%%e&set %%c=%%f))
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now