Computing.Net > Forums > Disk Operating System > if/then in bat file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

if/then in bat file

Reply to Message Icon

Name: mcahren
Date: September 12, 2003 at 20:41:26 Pacific
OS: win2k
CPU/Ram: intel 2.4 / 512mb
Comment:

I would like a bat file to copy files only if it is the first day of the month. I found an excellent post that is very close to what I need, but I'm not DOS savy enough to adapt it from day-of-week to day.

Thanks!!

McAhren

*********************************
Here is the post:

Name: Secret_Doom
Date: July 31, 2003 at 12:32:49 Pacific

@echo off
for /F "tokens=1" %%D in ('date/T') do set day=%%D
for %%D in (Sat Sun) do if /i "%day%"=="%%D" (set day=&goto:eof)
set day=
echo This part will not be executed on
echo Saturdays nor Sundays.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: September 13, 2003 at 06:03:44 Pacific
Reply:

The following script should fit your need:

@Echo Off
For /F "tokens=2 delims= /-" in ('Date /T') Do If not %%A==01 GoTo :EOF

Echo This command runs only if the first day of the month

The problem here is the Date format as it relays on the country settings; so the command I posted assumes the European format day dd/mm/yyyy, but in USA it is day mm-dd-yyyy leading to tokens=3. By the way under Windows XP the Date command returns no day of week, so tokens must be adjusted scaling by one.

Warning: be sure to insert a space after the = ending delims.

I hope this helps, otherwise post again.


0
Reply to Message Icon

Related Posts

See More


need help in schedualing Keyboard Buffer



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: if/then in bat file

script in .bat file www.computing.net/answers/dos/script-in-bat-file/12893.html

Changing Data of %choice% in .BAT File... www.computing.net/answers/dos/changing-data-of-choice-in-bat-file/16912.html

Printing in bat files www.computing.net/answers/dos/printing-in-bat-files/12009.html