Solved

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

Posted on 2004-09-08
5
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 85

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
Today’s effective marketing is about coming down to the customers’ level and engaging in a whole new way. A text message is one of the most effective and influential ways that you can engage your customers. Here are eight ways that you can utilize t…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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