Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using .GetLogDate acquired variable in a folder name

Posted on 2011-02-24
8
Medium Priority
?
671 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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