Solved

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

Posted on 2004-09-08
5
141 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:
rolutola 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

13 Experts available now in Live!

Get 1:1 Help Now