Solved

Using .GetLogDate acquired variable in a folder name

Posted on 2011-02-24
8
645 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

21 Experts available now in Live!

Get 1:1 Help Now