Solved

Using .GetLogDate acquired variable in a folder name

Posted on 2011-02-24
8
643 Views
Last Modified: 2012-05-11
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:

%.GetLogDate%
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?
0
Comment
Question by:Michael_Mulvaney
  • 5
  • 3
8 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 34970408
Why do you want to use GetLogDate???

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

Set TheDate=%DATE%

md %BackupDir%\%TheDate%

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

Open in new window

CopyToDateDir.cmd
0
 

Author Comment

by:Michael_Mulvaney
ID: 34976969
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:
http://thesystemguard.com/MtCmds/GetValue/GetLogDate.htm

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?
0
 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 34986965
You need ntlib.cmd To use GetLogDate!!!

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

ntlib(FREE)
http://thesystemguard.com/ntlib.asp

0
 

Author Comment

by:Michael_Mulvaney
ID: 34989933
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Closing Comment

by:Michael_Mulvaney
ID: 34989953
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.
0
 
LVL 19

Expert Comment

by:Thommy
ID: 34991192
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


GetDate.cmd
0
 
LVL 19

Expert Comment

by:Thommy
ID: 34991199
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...
0
 
LVL 19

Expert Comment

by:Thommy
ID: 34991203
By the way, thanks for the points...
:o)))
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

12 Experts available now in Live!

Get 1:1 Help Now