Solved

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

Posted on 2004-09-08
5
145 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 84

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

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…
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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