![]()
[<<]Message[>>] [<<]Author[>>] [<<]Subject[>>] [<<]Thread[>>]
Number : 9417 Date : 2004-12-03 Author : Garry Deane Subject : Re: Create and change to directory Size(KB) : 1
--- In xxcopy@yahoogroups.com, "rfitzva" wrote: > > I appreciate the quick response. > > It almost works, but I don't understand the commands well > enough to see what is wrong. > > set cmd=xxcopy /$yyyy-mm-dd-hhmm-ss$ /ec/l/zs > > evidently puts a string including the time stamp in cmd. > but echo %cmd% doesn't show it. > > The for loop shows it, but overwrites it. > C:\>for /F "tokens=2 skip=3" %a in ('xxcopy /$yyyy-mm-dd-hhmm-ss$ > /ec/l/zs') do > set tstamp=%a > C:\>set tstamp=2004-12-02-2212-32 > C:\>set tstamp=XXCOPY > C:\>set tstamp=have > C:\>set tstamp=for > C:\>set tstamp=suppress > C:\>set tstamp=the > C:\>set tstamp=any Ah, you're using the freeware version which issues a prompt when you use a macro. What you are seeing is the 2nd word of each line of the message that the freeware version issues. Assuming that you don't mind answering the macro prompt with a key press, use this instead. @echo off setlocal set cmd=xxcopy /$yyyy-mm-dd-hhmm-ss$ /ec/l/zs echo Press any key to continue for /f "tokens=2 skip=3" %%a in ('%cmd%') do ( set tstamp=%%a goto :next) :next echo %tstamp% It might be more convenient to not use xxcopy to get the timestamp. You can use the following to avoid the macro prompt. Note that this assumes W2k or higher and that your %date% and %time% settings are in the form DoW dd/mm/yyyy hh:mm:ss.cs. If your locale settings don't produce the DayofWeek or have the dd, mm, yyyy in a different order, you'll need to adjust the FOR variables to suit. for /f "tokens=1-8 delims=.-/: " %%a in ( 'echo %date% %time%') do (set tstamp=%%d-%%c-%%b-%%e%%f-%%g) echo %tstamp% BTW the reason you didn't see the value of %cmd% being set after the batch had completed is the use of the keyword SETLOCAL. This localises environment variables within the batch file and resets them to their original values when the batch encounters an ENDLOCAL or ends. For more information on the very powerful FOR command, type FOR /? in a Cmd window. Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.