03/03/2005 - Windows Command Line - Dates and Files

I've been having a need for while to get a dead simple way to create a dated directory just using a batch file in Windows 2K server. Because of the nature of what I'm doing I was try to stay away from using windows scripting.

Essentially each night I wanted to create a dated directory then copy some files into it. That way I could keep a months worth of versions of the files.

I've ended up finding a simple way that I hadn't seen before:

Here it is: (paste this into a batch file to see the results)

@echo off
set strdate=%Date:~-4,4%%Date:~-10,2%%Date:~-7,2%
set strtime=%Time:~0,2%%Time:~3,2%
echo %strdate% %strtime%

So if you want to create a directory with the date just add a line something like this to the end of the batch file above.

md %strdate%

Hope this is useful.


back...

You can chat to me live. If I'm online it will say Live Help: Available, click that to chat.
 
My Work   ::   Blog Archive   ::   Gallery   ::   Resources   ::   About me
Copyright © Phil Wilding 1975-2005
You cannot reproduce any information on this site without the written permission of Phil Wilding.
stumbleupon