dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
707
share rss forum feed


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4

Batch file question

I need the expertise of someone who knows how to do batch files.

I have a batch file that runs each night at 11:55pm. This file moves txt files from an IBM I Series server to a share on a Windows Server.

It's worked very well over the past two years. However, I'm needing help making some changes. The database re-org that occurs each night now runs well past midnight, so I need to edit this Batch file so that it reads the date, then steps back one day and creates a folder.

As it is now, it reads the date then creates a folder based on the date. Once the folder is created it then moves the necessary files in to that folder. Now that it is running after midnight, I need it to create a folder that uses the date from the day before.

Is this even possible?

Ex:

REM @ECHO OFF
rem Discover Date & Set Variables
for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set Month=%%j
set Day=%%k
set Year=%%l
)
Rem
Rem

REM BEGIN MOVE

X:
cd ENDDAY
cd BR01
md .\%Year%%Month%%Day%
cd %Year%%Month%%Day%
move /Y Q:\01\W1\DATABASE\*.*

cd X:\ENDDAY\BR02
md .\%Year%%Month%%Day%
cd %Year%%Month%%Day%
move /Y Q:\02\W1\DATABASE\*.*

cd X:\ENDDAY\BR03
md .\%Year%%Month%%Day%
cd %Year%%Month%%Day%
move /Y Q:\03\W1\DATABASE\*.*

Thansk,
B.
--
One Big Ass Mistake America


drslash
Goya Asma
Premium
join:2002-02-18
Marion, IA
You should be able to run a batch before midnight that outputs the date and then the after midnight batch can read that in.


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4
reply to rudnicke
So if I ran the first part of this batch file in a separate batch file, would it retain the previous date when the next batch ran an hour later? Does it retain that information for that long?
--
One Big Ass Mistake America


drslash
Goya Asma
Premium
join:2002-02-18
Marion, IA
reply to rudnicke
easier still would be to just run a batch before midnight to create the directory. The name of the directory would need to be save in a .txt file that the after midnight batch reads.


Kilroy
Premium,MVM
join:2002-11-21
Saint Paul, MN
reply to rudnicke
You'll increase the size of the batch greatly trying to subtract a day, to account for the first of the month. Run it at 11:55 and add a pause until the file is done - batch file wait examples

i.e.
PING 127.0.0.1 -n 1 -w 3600000 >NUL

That will wait an hour until running the next line.
--
“Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.” ¯ Robert A. Heinlein


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4
Thanks. I'll give that shot.

OZO
Premium
join:2003-01-17
kudos:2
reply to Kilroy
said by Kilroy:

PING 127.0.0.1 -n 1 -w 3600000 >NUL

That will wait an hour until running the next line.

No, it will not. It's because:
-w timeout Timeout in milliseconds to wait for each reply.
And reply from local loopback comes almost immediately.Thus, no delay...

The proper way to make delay with ping is:
ping 127.0.0.1 -n 3601 > nul
Now, that will give you delay 3600 sec. Note, that in order to get 3600 sec delay, you should increment 3600 by one...
--
Keep it simple, it'll become complex by itself...