Solved

Using .GetLogDate acquired variable in a folder name

Posted on 2011-02-24
8
651 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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