Using .GetLogDate acquired variable in a folder name

I want to run a batch file that creates a folder that has as its name today's date and then to copy to that folder the contents of another directory.

I am apparently unable to retrieve the variable acquired from the command .GetLogDate.

My operating system is Windows 2003 Server SBS.

I have searched Experts-Exchange for an answer but the most help was in this thread:

    * Experts Exchange
    * OS
    * Microsoft OS
    * Windows OS
    * Windows 2000
    * Manipulating strings in a Windows 2000 batch file.

However, I had already visited the linked site and tried out what I found there, to no avail.

I am using this script:

md E:\Backup\%#LogDate%\V
robocopy D:\V E:\Backup\%#LogDate%\V /E  /W:2 /R:2

When I run the script a new directory 'V' is made in E:\Backup. The '%#LogDate%' is ignored. After the new directory is made, the robocopy command works fine and, again ignoring the '%#LogDate%' in the path, files are copied from D:\V to E:\Backup\V.

How can I set this variable and use it to name a folder?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

ThommyConnect With a Mentor Commented:
You need ntlib.cmd To use GetLogDate!!!

Have you already ordered it by e-mail????


Why do you want to use GetLogDate???

A simple batch script will do it for you...
@echo off
Set BackupDir=E:\BACKUP

Set TheDate=%DATE%

md %BackupDir%\%TheDate%

xcopy D:\V\*.* %BackupDir%\%TheDate%\V /I

Open in new window

Michael_MulvaneyAuthor Commented:
Thanks for the reply

1) "Why do you want to use GetLogDate???"
Because I have seen a couple of posts on the internet refer to this site:

2) "A simple batch script will do it for you..."
I thought that I already had a simle batch script, albeit one that did not do as I wanted.

3) "xcopy D:\V\*.* %BackupDir%\%TheDate%\V /I"
Isn't robocopy superior to xcopy?
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Michael_MulvaneyAuthor Commented:
Oh, I see! So, it seems that this 'ntlib.cmd' somehow augments the number of commands natively available from the DOS library that is available from Windows. I had not picked that up when I was reading comments in other posts: thanks for clarifying that.

I have studied your original reply, thanks, and putting that with some posts that I have seen elsewhere I realise that the command to call the date is, as you wrote, '%Date%'. However, if I call the date using %Date%, the output is of the form 25/02/2011, for example. Which is the advantage of .GetLogDate, I suppose, as it does not output the delimiters.

I have so spend a little time, it seems, to add extra lines of code to remove the delimiters. I am studying how to do that and at the moment the best way forward seems to be using 'For' and 'Token'.

Thanks for pointing out that .GetLogDate is only available if I add this extra functionality to my DOS command set and for pointing out that the native command for calling the date in DOS is %Date%, although I have to format it to use it in a file name. I guess that if a system is set up to use dashes as delimiters, that problem does not arise. Maybe I should think about that as an option.
Michael_MulvaneyAuthor Commented:
The second post from the only person who replied told me why I could not use .GetLogDate unless I add ntlib.cmd - surely it would have been wirth mentioning in the beginning.
The script provided as an example suggested that I use XCopy instead of robocopy but that seems not a good idea.
Also, having pointed me in the direction of using %Date%, that fact that that there was no comment that this will not work if my system uses '/' as delimiters would seem to be a significant omission.
Anyway, the replies were helpful and when added with the information found elsewhere allowed me to move forward.
To eliminate the delimiters an get the date in the format "YYYYMMDD" you can go as follows:

FOR /F "tokens=1,2,3 delims=/. " %%a in ('date /T') do set TheDate=%%c%%b%%a

But keep in mind, the batch from my last post for retrieving the date depends on your system settings!!!

If you like i can also provide a more complicated batch script, which checks system settings in registry and thus always builds the correct date string independant of your system date format...
By the way, thanks for the points...
All Courses

From novice to tech pro — start learning today.