How to code a batch file?

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Guest
Does anyone have any suggestions on how to code a batch file to open an excel

file if current time is between 9 am and 10 am? otherwise don't open it.

Thanks in advance for any suggestions

Eric
 
On Mar 25, 8:37 pm, Eric wrote:

> Does anyone have any suggestions on how to code a batch file to open an excel

> file if current time is between 9 am and 10 am? otherwise don't open it.

> Thanks in advance for any suggestions

> Eric




I would try this group.



Andy



http://groups.google.com/group/alt.msdos.batch.nt?hl=en
 
Eric wrote:

> Does anyone have any suggestions on how to code a batch file to open an excel

> file if current time is between 9 am and 10 am? otherwise don't open it.

> Thanks in advance for any suggestions




Here you go:



=======================================================================

@echo off

for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

if /i %tm% LSS 900 goto eof

if /i %tm% GTR 1000 goto eof

"x:\Data Folder\FileName.xls"



=======================================================================



John
 
Thank everyone very much for suggestions

Could you please give me any suggestions on how to add following condition

into batch file?

If (today is tuesday or wednesday or thursday or friday) and current time is

between 9 am to 10 am then

open D:/file.xls

Do you have any suggestions?

Thank everyone very much for any suggestions

Eric



"John John - MVP" wrote:



> Eric wrote:

> > Does anyone have any suggestions on how to code a batch file to open an excel

> > file if current time is between 9 am and 10 am? otherwise don't open it.

> > Thanks in advance for any suggestions


>

> Here you go:

>

> =======================================================================

> @echo off

> for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

> if /i %tm% LSS 900 goto eof

> if /i %tm% GTR 1000 goto eof

> "x:\Data Folder\FileName.xls"

>

> =======================================================================

>

> John

> .

>
 
Eric wrote:

> Thank everyone very much for suggestions

> Could you please give me any suggestions on how to add following condition

> into batch file?

> If (today is tuesday or wednesday or thursday or friday) and current time is

> between 9 am to 10 am then

> open D:/file.xls

> Do you have any suggestions?

> Thank everyone very much for any suggestions






If you only want to open a file on Friday and on no other day:



======================================================================

@echo off

for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

if /i %tm% LSS 900 goto eof

if /i %tm% GTR 1000 goto eof

if /i %day%==fri goto friday

goto :eof



:friday

"D:/file1.xls"



======================================================================







If you want to open different files based on day or the week:



======================================================================

@echo off

for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

if /i %tm% LSS 900 goto eof

if /i %tm% GTR 1400 goto eof

if /i %day%==sun goto sunday

if /i %day%==mon goto monday

if /i %day%==tue goto tuesday

if /i %day%==wed goto wednesday

if /i %day%==thu goto thursday

if /i %day%==fri goto friday

if /i %day%==sat goto saturday



:sunday

"D:/file1.xls"

goto :eof



:monday

"D:/file2.xls"

goto :eof



:tuesday

"D:/file3.xls"

goto :eof



:wednesday

"D:/file4.xls"

goto :eof



:thursday

"D:/file5.xls"

goto :eof



:friday

"D:/file6.xls"

goto:eof



:saturday

"D:/file7.xls"



======================================================================



John
 
PS:



The command window will stay open (minimized to the taskbar). You can

use the START command to avoid this, example:



====================================================================

@echo off

for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

if /i %tm% LSS 900 goto eof

if /i %tm% GTR 1000 goto eof

if /i %day%==fri goto friday

goto :eof



:friday

start "C:\Program Files\Lotus\123\123w.exe" "E:\123DATA\PAYROLL.123"



=======================================================================



John





John John - MVP wrote:

> Eric wrote:

>> Thank everyone very much for suggestions

>> Could you please give me any suggestions on how to add following

>> condition into batch file?

>> If (today is tuesday or wednesday or thursday or friday) and current

>> time is between 9 am to 10 am then

>> open D:/file.xls

>> Do you have any suggestions?

>> Thank everyone very much for any suggestions


>

>

> If you only want to open a file on Friday and on no other day:

>

> ======================================================================

> @echo off

> for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

> for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

> if /i %tm% LSS 900 goto eof

> if /i %tm% GTR 1000 goto eof

> if /i %day%==fri goto friday

> goto :eof

>

> :friday

> "D:/file1.xls"

>

> ======================================================================

>

>

>

> If you want to open different files based on day or the week:

>

> ======================================================================

> @echo off

> for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

> for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

> if /i %tm% LSS 900 goto eof

> if /i %tm% GTR 1400 goto eof

> if /i %day%==sun goto sunday

> if /i %day%==mon goto monday

> if /i %day%==tue goto tuesday

> if /i %day%==wed goto wednesday

> if /i %day%==thu goto thursday

> if /i %day%==fri goto friday

> if /i %day%==sat goto saturday

>

> :sunday

> "D:/file1.xls"

> goto :eof

>

> :monday

> "D:/file2.xls"

> goto :eof

>

> :tuesday

> "D:/file3.xls"

> goto :eof

>

> :wednesday

> "D:/file4.xls"

> goto :eof

>

> :thursday

> "D:/file5.xls"

> goto :eof

>

> :friday

> "D:/file6.xls"

> goto:eof

>

> :saturday

> "D:/file7.xls"

>

> ======================================================================

>

> John
 
I finished the rest code on the other day, does it look right?

Thank everyone very much for any suggestions

Eric



======================================================================

@echo off

for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

if /i %tm% LSS 900 goto eof

if /i %tm% GTR 1000 goto eof

if /i %day%==tue goto tuesday

if /i %day%==wed goto wednesday

if /i %day%==thu goto thursday

if /i %day%==fri goto friday

goto :eof



:tuesday

:wednesday

:thursday

:friday

"D:/file1.xls"



======================================================================



"John John - MVP" wrote:



> Eric wrote:

> > Thank everyone very much for suggestions

> > Could you please give me any suggestions on how to add following condition

> > into batch file?

> > If (today is tuesday or wednesday or thursday or friday) and current time is

> > between 9 am to 10 am then

> > open D:/file.xls

> > Do you have any suggestions?

> > Thank everyone very much for any suggestions


>

>

> If you only want to open a file on Friday and on no other day:

>

> ======================================================================

> @echo off

> for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

> for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

> if /i %tm% LSS 900 goto eof

> if /i %tm% GTR 1000 goto eof

> if /i %day%==fri goto friday

> goto :eof

>

> :friday

> "D:/file1.xls"

>

> ======================================================================

>

>

>

> If you want to open different files based on day or the week:

>

> ======================================================================

> @echo off

> for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

> for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

> if /i %tm% LSS 900 goto eof

> if /i %tm% GTR 1400 goto eof

> if /i %day%==sun goto sunday

> if /i %day%==mon goto monday

> if /i %day%==tue goto tuesday

> if /i %day%==wed goto wednesday

> if /i %day%==thu goto thursday

> if /i %day%==fri goto friday

> if /i %day%==sat goto saturday

>

> :sunday

> "D:/file1.xls"

> goto :eof

>

> :monday

> "D:/file2.xls"

> goto :eof

>

> :tuesday

> "D:/file3.xls"

> goto :eof

>

> :wednesday

> "D:/file4.xls"

> goto :eof

>

> :thursday

> "D:/file5.xls"

> goto :eof

>

> :friday

> "D:/file6.xls"

> goto:eof

>

> :saturday

> "D:/file7.xls"

>

> ======================================================================

>

> John

> .

>
 
From: "Eric"



| Thank everyone very much for suggestions

| Could you please give me any suggestions on how to add following condition

| into batch file?

| If (today is tuesday or wednesday or thursday or friday) and current time is

| between 9 am to 10 am then

| open D:/file.xls

| Do you have any suggestions?

| Thank everyone very much for any suggestions

| Eric



Again...



Use the system Task Scheduler !



No programming logic needed -- KISS !





--

Dave

http://www.claymania.com/removal-trojan-adware.html

Multi-AV - http://www.pctipp.ch/downloads/dl/35905.asp
 
From: "Eric"



| I finished the rest code on the other day, does it look right?

| Thank everyone very much for any suggestions

| Eric



This is too funny...



Writing a BAT file for this is like swatting a fly with a sledge hammer.



The Task Scheduler is the easiest approach as *IT* will automatically do what you want at

a given time on a given day!





--

Dave

http://www.claymania.com/removal-trojan-adware.html

Multi-AV - http://www.pctipp.ch/downloads/dl/35905.asp
 
"David H. Lipman" wrote in message

news:OFCVMZUzKHA.4752@TK2MSFTNGP04.phx.gbl...

> From: "Eric"

>

> | I finished the rest code on the other day, does it look right?

> | Thank everyone very much for any suggestions

> | Eric

>

> This is too funny...

>

> Writing a BAT file for this is like swatting a fly with a sledge hammer.

>

> The Task Scheduler is the easiest approach as *IT* will automatically do

> what you want at

> a given time on a given day!

>

>

> --

> Dave

> http://www.claymania.com/removal-trojan-adware.html

> Multi-AV - http://www.pctipp.ch/downloads/dl/35905.asp

>




Dave,



Don't get yourself agitated. Eric is a moron that cannot follow simple

instructions. He multiposts all over the place. Read PA Bear's post above.

Check the microsoft.public.excel.programming NG and search 'Eric'.



Apparently, Eric has the mind of a houseplant and the mentality of a stepped

on potato chip. He needs his Thorazine dose increased dramatically or just

changed over to Risperdal. He'll post anything, anywhere as long as his

handcuffs are off. I know. I'm his doctor.



BB
 
David H. Lipman wrote:

> From: "Eric"

>

> | Thank everyone very much for suggestions

> | Could you please give me any suggestions on how to add following condition

> | into batch file?

> | If (today is tuesday or wednesday or thursday or friday) and current time is

> | between 9 am to 10 am then

> | open D:/file.xls

> | Do you have any suggestions?

> | Thank everyone very much for any suggestions

> | Eric

>

> Again...

>

> Use the system Task Scheduler !

>

> No programming logic needed -- KISS !

>

>




"KISS" even has its own article :-)



http://en.wikipedia.org/wiki/KISS_principle



Paul
 
David H. Lipman wrote:

> From: "Eric"

>

> | I finished the rest code on the other day, does it look right?

> | Thank everyone very much for any suggestions

> | Eric

>

> This is too funny...

>

> Writing a BAT file for this is like swatting a fly with a sledge hammer.

>

> The Task Scheduler is the easiest approach as *IT* will automatically do what you want at

> a given time on a given day!




But keep in mind that the scheduled task will run at the designated time

on the designated day whether you need to run it or not, and that it may

open files whether you want to work on them or not, or whether you are

at the computer or not. With the batch file you can run this at your

own time, like at 9:45 instead of 9:00, or not at all if there is

nothing to do with the file.



John
 
Eric wrote:

> I finished the rest code on the other day, does it look right?




No, you put the labels (:tuesday, :wednesday...) but you didn't put any

commands under the labels (except for the :friday label) and you didn't

put a goto at the end of the labels so the batch file will keep on

processing down the list of labels regardless of the day of the week.

Also, being that you're opening the same file ("D:/file1.xls")

regardless of the day so you can shorten the batch file with one label

only, try this instead:





======================================================================

@echo off

for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

if /i %tm% LSS 900 goto eof

if /i %tm% GTR 1000 goto eof

if /i %day%==tue goto openfile

if /i %day%==wed goto openfile

if /i %day%==thu goto openfile

if /i %day%==fri goto openfile

goto :eof



:openfile

"D:/file1.xls"



======================================================================



John
 
BillyBob wrote:

>>> I finished the rest code on the other day, does it look right?

>>> Thank everyone very much for any suggestions

>>> Eric


>>

>> This is too funny...

>>

>> Writing a BAT file for this is like swatting a fly with a sledge hammer.

>>

>> The Task Scheduler is the easiest approach as *IT* will automatically do

>> what you want at

>> a given time on a given day!

>>


>

> Dave,

>

> Don't get yourself agitated. Eric is a moron that cannot follow simple

> instructions. He multiposts all over the place. Read PA Bear's post

> above.

> Check the microsoft.public.excel.programming NG and search 'Eric'.

>

> Apparently, Eric has the mind of a houseplant and the mentality of a

> stepped

> on potato chip. He needs his Thorazine dose increased dramatically or

> just

> changed over to Risperdal. He'll post anything, anywhere as long as his

> handcuffs are off. I know. I'm his doctor.




Screenwipes, please.



Paging Nurse Ratchet...
 
Thanks a lot for suggestions

Eric



"John John - MVP" wrote:



> Eric wrote:

> > I finished the rest code on the other day, does it look right?


>

> No, you put the labels (:tuesday, :wednesday...) but you didn't put any

> commands under the labels (except for the :friday label) and you didn't

> put a goto at the end of the labels so the batch file will keep on

> processing down the list of labels regardless of the day of the week.

> Also, being that you're opening the same file ("D:/file1.xls")

> regardless of the day so you can shorten the batch file with one label

> only, try this instead:

>

>

> ======================================================================

> @echo off

> for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

> for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

> if /i %tm% LSS 900 goto eof

> if /i %tm% GTR 1000 goto eof

> if /i %day%==tue goto openfile

> if /i %day%==wed goto openfile

> if /i %day%==thu goto openfile

> if /i %day%==fri goto openfile

> goto :eof

>

> :openfile

> "D:/file1.xls"

>

> ======================================================================

>

> John

> .

>
 
"PA Bear [MS MVP]" wrote in message

news:OVAEPPXzKHA.2436@TK2MSFTNGP04.phx.gbl...

> BillyBob wrote:

>>>> I finished the rest code on the other day, does it look right?

>>>> Thank everyone very much for any suggestions

>>>> Eric

>>>

>>> This is too funny...

>>>

>>> Writing a BAT file for this is like swatting a fly with a sledge hammer.

>>>

>>> The Task Scheduler is the easiest approach as *IT* will automatically do

>>> what you want at

>>> a given time on a given day!

>>>


>>

>> Dave,

>>

>> Don't get yourself agitated. Eric is a moron that cannot follow simple

>> instructions. He multiposts all over the place. Read PA Bear's post

>> above.

>> Check the microsoft.public.excel.programming NG and search 'Eric'.

>>

>> Apparently, Eric has the mind of a houseplant and the mentality of a

>> stepped

>> on potato chip. He needs his Thorazine dose increased dramatically or

>> just

>> changed over to Risperdal. He'll post anything, anywhere as long as his

>> handcuffs are off. I know. I'm his doctor.


>

> Screenwipes, please.

>

> Paging Nurse Ratchet...




LOL. FYI, she's my wife



Cheers,



R.P "BillyBob" McMurphy
 
From: "Paul"



| David H. Lipman wrote:

>> From: "Eric"




>> | Thank everyone very much for suggestions

>> | Could you please give me any suggestions on how to add following condition

>> | into batch file?

>> | If (today is tuesday or wednesday or thursday or friday) and current time is

>> | between 9 am to 10 am then

>> | open D:/file.xls

>> | Do you have any suggestions?

>> | Thank everyone very much for any suggestions

>> | Eric




>> Again...




>> Use the system Task Scheduler !




>> No programming logic needed -- KISS !








| "KISS" even has its own article :-)



| http://en.wikipedia.org/wiki/KISS_principle



| Paul



:-)



--

Dave

http://www.claymania.com/removal-trojan-adware.html

Multi-AV - http://www.pctipp.ch/downloads/dl/35905.asp
 
You're welcome.



John



Eric wrote:

> Thanks a lot for suggestions

> Eric

>

> "John John - MVP" wrote:

>

>> Eric wrote:

>>> I finished the rest code on the other day, does it look right?


>> No, you put the labels (:tuesday, :wednesday...) but you didn't put any

>> commands under the labels (except for the :friday label) and you didn't

>> put a goto at the end of the labels so the batch file will keep on

>> processing down the list of labels regardless of the day of the week.

>> Also, being that you're opening the same file ("D:/file1.xls")

>> regardless of the day so you can shorten the batch file with one label

>> only, try this instead:

>>

>>

>> ======================================================================

>> @echo off

>> for /f "tokens=1 delims=/.- " %%A in ('echo %date%') do (set day=%%A)

>> for /f "tokens=1-2 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b)

>> if /i %tm% LSS 900 goto eof

>> if /i %tm% GTR 1000 goto eof

>> if /i %day%==tue goto openfile

>> if /i %day%==wed goto openfile

>> if /i %day%==thu goto openfile

>> if /i %day%==fri goto openfile

>> goto :eof

>>

>> :openfile

>> "D:/file1.xls"

>>

>> ======================================================================

>>

>> John

>> .

>>
 
Back
Top