Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Is this batch code correct?  (Read 3530 times)

0 Members and 1 Guest are viewing this topic.

Alkamar

    Topic Starter


    Rookie

    Is this batch code correct?
    « on: July 06, 2010, 03:07:41 PM »
    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) copied

    Dusty



      Egghead

    • I could if she would, but she won't so I don't.
    • Thanked: 75
    • Experience: Beginner
    • OS: Windows XP
    Re: Is this batch code correct?
    « Reply #1 on: July 06, 2010, 07:40:13 PM »
    Quote 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.
    « Last Edit: July 06, 2010, 07:59:07 PM by Dusty »
    One good deed is worth more than a year of good intentions.

    Alkamar

      Topic Starter


      Rookie

      Re: Is this batch code correct?
      « Reply #2 on: July 06, 2010, 08:19:05 PM »
      Ah, wow. I wasn't even thinking I guess. ;D

      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. :)