Solved

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

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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…
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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