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

Author Topic: Is this possible with a batch file?  (Read 3237 times)

0 Members and 1 Guest are viewing this topic.

hendrikbez

    Topic Starter


    Greenhorn

    Is this possible with a batch file?
    « on: March 27, 2012, 01:08:04 AM »
    I have a bat file one for every day that runs, with system scheduler, so for each bat file I have to run system scheduler.
    Is there a way that I can only run system scheduler one. but the bat file give the day.

    How can I do this.

    Eg
    Here is Day 1 (Busres 1(Mon).bat)

    @echo off
    net use K: \\172.22.6.36\osback
    :: [To Connect(map) K: drive with ip]
    cd\
    echo off
    K:
    cd \
    Xcopy . /D /I /F /E /Y D:\Backup\Busres\1Mon
    net use K: /delete /y
    :: [To disconnect the K: Drive]
    exit


    Here is day 2 Busres 2(Tue).bat

    @echo off
    net use K: \\172.22.6.36\osback
    :: [To Connect(map) K: drive with ip]
    cd\
    echo off
    K:
    cd \
    Xcopy . /D /I /F /E /Y D:\Backup\Busres\2Tue
    net use K: /delete /y
    :: [To disconnect the K: Drive]
    exit

    Can I make one batch file so that it can run on day 1,2,3,4,5,6 and 7.

    Thank You

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Is this possible with a batch file?
    « Reply #1 on: March 27, 2012, 08:26:12 AM »
    Since you posted this over on the DosTips forums as well I will just quote what they told you over there.  Basically comes down to if your regional settings display the Day of the Week with the DATE variable.  Otherwise there are ways to get the day of the week with VBscript as well.
    Quote from: foxidrive
    Yes it is possible but it is specific to your locale and regional settings

    When I echo the %date% variable I get this:

    Code: [Select]
    D:\>echo %date%
    Tue 27/03/2012

    so I can set a variable to the first token in the %date% variable

    Code: [Select]
    @echo off
    for /f "tokens=1" %%a in ("%date%") do set day=%%a
    echo %day%

    With some extra logic you can add a number from 1 to 7

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Is this possible with a batch file?
    « Reply #2 on: March 27, 2012, 06:00:51 PM »
    There are third party programs that can help you. Or you can make one in C++ or a similar language. Or, just use power shell instead o batch.

    Anyway, here is the concept. Thee is a standard thing the in DOS API that gives you the local date using some numbers instead of words. The days of the week are numbered from 1 to 7, with Sunday being day one.

    There is one program that does the following at the command line. I mean I know of one. There are, likely, many others.

    SayToday quotelist

    It then gives a message from quote list, a text file that is delimited in seven parts. Only the part that is for the current day of week is displayed.

    The quote list is often used for a quote of the day for users who sign on to the network. But that message could be sent to a batch file tat will be inked after the SayToday program terminates.
    Maybe like this:
    Code: [Select]
    saytoday joblist >job.bat
    job
    That way job.bat is different each day of the week. Making is different each day of  the year would be another task.




    « Last Edit: March 27, 2012, 06:13:37 PM by Geek-9pm »