1.

Solve : Is this batch code correct??

Answer»

Code: [Select]SET dd=%date% %Time%
SET today=%dd:~4,2%
SET post=.%dd:~7,2%.%dd:~12,2%
SET /A ex1=%today%-1
SET ex2=%ex1%%post%
XCOPY "%HOMEDRIVE%%HOMEPATH%\Documents\My Dropbox\server\Mysql Backup\85 OS*%ex2% 23.5*\*.*" C:\xampp\mysql\data\serverT\ /S
What I'm trying to do, is GRAB all the files in a directory that is created daily with a timestamp. the SET /A ex1=%today%-1 minuses the current day by 1, making it yesterday. then I use the variables created beforehand in a xcopy command, I'm GETTING problems though, it seems to want to use the wildcards "*" as an actual part of the file name, that is not at all what I figured wildcards were meant to do. But it LOOKS for "85 OS*6.06.10 23.5*\*.*" Am I missing something?

Code: [Select]File not found - *.*
0 File(s) copiedQuote from: Alkamar

SET /A ex1=%today%-1 minuses the current day by 1, making it yesterday.

This is not possible when using dates. If the current day is 01 the outcome will be 0 and if the current day is 08 or 09 Set /A will fail because it will 'see' the date as Octal (base eight), in Octal 8 and 9 are invalid. Also, if today is the first day of the month and you want to get yesterday's date, the month and possibly the year must be decremented as well as the day.

e.g. (Based on a date format of dd/mm/yyyy)
Current date = 01/01/2010
Current date -1 = 31/12/2009

and

Current date = 01/03/2010
Current date -1 = 28/02/2010

To manipulate dates and times I suggest you consider VB scripting.

Below is a small script combining batch scripting and VB scripting which will reduce the date by one day.
Code: [Select]@echo off
setlocal
cls

set vbs=%temp%\vbs.vbs

> %vbs% echo WScript.Echo DateAdd("d",-1,Date)

for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do (
set newdate=%%a
)
del %vbs%
echo Newdate=%newdate%
exit /b

Hope this helps.Ah, wow. I wasn't even thinking I guess.

Well, this definitely helps, I don't know a single thing about VB or VBS, but I'll see what I can do. Thanks Dusty.


Discussion

No Comment Found